Tuesday, June 29, 2010

A Simple Event handler

A Simple Event handler

Creating a simple Event handler – inheriting SPEventReceivers such as SPItemEventReceiver, SPListEventReceiver


 


Feature File

<?xml
version="1.0"
encoding="utf-8"?>

<Feature
Scope="Web"

Title="Simple Event Handler Registration"

Id="69322A1C-0618-43eb-813B-82F02CBA9634"

xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>

<ElementManifest
Location="Elements.xml"/>

</ElementManifests>

</Feature>

-------------------
Elements File
<?xml
version="1.0"
encoding="utf-8"?>

<Elements
xmlns="http://schemas.microsoft.com/sharepoint/">

<Receivers
ListTemplateId="104">

<Receiver>

<Name>MyEventHandlers</Name>

<Type>ItemDeleting</Type>

<SequenceNumber>10000</SequenceNumber>

<Assembly>SDKSPEvents, Version=1.0.0.0, Culture=neutral, PublicKeyToken=89d0c098ec698224</Assembly>

<Class>SDKSPEvents.SimpleEventHandler</Class>

<Data></Data>

<Filter></Filter>

</Receiver>

</Receivers>

</Elements>

-----------

Now the class file implementing the SPItemEventReceiver for item level event handling. All the levels have their respective EventReceiver (ex. SPListEventReceiver)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

namespace SDKSPEvents

{


public
class
SimpleEventHandler : SPItemEventReceiver

{


 


public
override
void ItemDeleting(SPItemEventProperties properties)

{


//base.ItemDeleting(properties);

properties.Cancel = true;

properties.ErrorMessage = "Deleting not Permitted";

}

}


 


 


public
class
sim : SPListEventReceiver

{


public
override
void FieldDeleting(SPListEventProperties properties)

{

properties.Cancel = true;

properties.ErrorMessage = "Deleting not Permitted";

}

}

}

................HaPpY CoDinG


 

Partha (Aurum)

Thursday, June 24, 2010

STSADM RESTORE – Exception from HRESULT: 0x80040E14


 

Exception from HRESULT: 0x80040E14

I was trying to restore my site in a different box with the stsadm restore command :

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>

stsadm.exe -o restore -url http://Server:7777 -filename "D:\Partha\Backup\MyAppCom.dat" –overwrite


 

This resulted to an exception Exception from HRESULT: 0x80040E14

While trying to dig the problem, I found that my SQL server has run out of space for either the logs or the data files. Actually my D: drive ran out of space…. L. The solution was very simple deleted some not required files and copied few to other drives to make some space for SQL Server, ran the command and the restore was successful.


 

………………..HaPpY CoDiNg

Partha (Aurum)

Monday, June 21, 2010

Install.bat for VS 2008

Install.bat

A ready to use install.bat. The Xcopy part has been fully defined since it was not working properly in VS2008.


 

@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template"

@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"

@SET GACUTIL="C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\GacUtil.exe"


 

Echo Copying files to TEMPLATE directory

xcopy "C:\Partha\Devarea\MyFeatureReceiver\MyFeatureReceiver1\MyFeatureReceiver1\TEMPLATE\*" "c:\program files\common files\microsoft shared\web server extensions\12\Template" /e /y


 

REM Echo Installing feature

REM %STSADM% -o InstallFeature -filename MyFeatureReceivers\feature.xml -force


 

REM Echo Uninstalling the DLL from GAC

REM %GACUTIL% /u MyFeatureReceiver1


 

Echo Installing the DLL in GAC

Echo %GACUTIL%

%GACUTIL% /i "C:\Partha\Devarea\MyFeatureReceiver\MyFeatureReceiver1\MyFeatureReceiver1\bin\Debug\MyFeatureReceivers.dll"


 

REM Echo Restart IIS Worker Process IISRESET

REM IISRESET


 


 

http://blah.winsmarts.com/2008-7-Authoring_SharePoint_2007_Workflows_using_VS2008.aspx

http://msdn.microsoft.com/en-us/library/bb466224(office.12).aspx

Deployment - Xcopy

Deployment has always been a pain area for SharePoint developers. However the good news is in SharePoint 2010 the deployment process has eased off a lot. Although the use of WSP
Builder also helps a lot for creating wsp solution packages for deployment. But during the development phase it still remains a cumbersome job for copying different file in different folder such as the putting the assemblies in the GAC or a BIN folder. I reduce this redundant process I prefer to use the install.bat file where I keep all my post build commands (incase the solution is big) otherwise, I keep the commands in the post build. Let us see the below example – here, I am putting the dlls in a separate folder Deployment\bin and other pages such as aspx, ascx in Deployment\Pages and Deployment\UserControls respectively.

The Deployment folder is in C drive:-

C:\Work\Projects\Deployment\bin

xcopy /y "$(TargetDir)*.dll" "C:\Projects\Deployment\bin\*.dll"

xcopy /y "$(projectdir)*.aspx" "C:\Projects\Deployment\Pages\*.aspx"

xcopy /y "$(projectdir)*.ascx" "C:\Projects\Deployment\UserControls\*.ascx"

On successful build of the project, this script will copy the required dlls and file at designated folder… Hope this information might help other… J

More information on XCopy:

http://commandwindows.com/xcopy.htm, http://www.15seconds.com/Issue/030806.htm, http://support.microsoft.com/kb/326355

……. HaPpY CoDinG

Partha (Aurum)


 

Wednesday, June 16, 2010

Screen Scraping

Screen Scraping (web response) with web request object


 

If you need to intercept the response stream from any url which in other words said as Screen Scraping. In the below example I have created a uri object to create a Webrequest.Create(strUrl).

Uri url = new
Uri("http://www.google.com");

WebRequest wr = WebRequest.Create(url);

WebResponse response = wr.GetResponse();

StreamReader sr = new
StreamReader (response.GetResponseStream ());

string result = sr.ReadToEnd();

Response.Write(result);


 

Note: Before accessing the url try with TelNet and check whether the url is sending any response.


 

……. HaPpY CoDinG

Partha (Aurum)

Tuesday, June 15, 2010

Getting Assemblies from GAC

Assemblies from GAC

At times we face situations wherein we need the dlls or assemblies directly. Generally the assemblies reside in the Assembly Folder which is best known as GAC (Global Assembly Cache). To open the GAC – go to run and write "assembly" (without quotes), this will open a folder at location "C:\WINDOWS\assembly". This is where we can find all the assemblies listed. Now if we would like to get the dll or assembly rather than the reference, then what..? L I tried to copy the dll.. upps.!! It will not work….

Finally found a way out to get upto the dll --- J

Steps –

  1. Go to run and write "c:\WINDOWS\assembly\gac_msil"
  2. This will open a folder where we can find the assembly folders.

For simplicity let us take and example to find the mostly used dll for SharePoint – Microsoft.SharePoint.dll . We would use the same command from the run, we could find a folder named Microsoft.SharePoint. This is the folder that contains the dll. @ C:\WINDOWS\assembly\gac_msil\Microsoft.SharePoint. On clicking the folder we would land on the folder named 12.0.0.0__71e9bce111e9429c, this is folder name shows the version number+_+ public key token ( we can get the public key token from this place as well, however this is not recommended) and inside this folder (C:\WINDOWS\assembly\gac_msil\Microsoft.SharePoint\12.0.0.0__71e9bce111e9429c)we get the desired dll - Microsoft.SharePoint.dll


 

Hope this information helps other…..

……. HaPpY CoDinG

Partha (Aurum)

GACUtil missing in Windows Server 2008/Visual Studio 2008

GACUtil missing in Windows Server 2008/Visual Studio 2008

I was developing a webpart in Visual Studio 2008 on Windows Server 2008 to be deployed in a SharePoint Site. While writing the install.bat, I could not configure my post build for my class library in Visual Studio 2008 to be deployed in GAC. The Gacutil was not found at the location – "" I wrote the Gacutil path as I used to do for Visual Studia 2005.

@SET GACUTIL="C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\GacUtil.exe"

And in the Post Build Option

cd $(ProjectDir)
Install.bat

Thus, I had to look for Gacuitl.exe's path. I searched into directories below and I was surprised that it was no where to be found.....

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\GacUtil.exe

C:\Program Files\Microsoft Visual Studio 9.0\SDK\v3.5\Bin // NOT FOUND

C:\Program Files\Microsoft Visual Studio 9.0 // NOT FOUND

C:\Program Files\Microsoft.NET // NOT FOUND

Then I searched into C:\Windows\Microsoft.NET\Framework and found out gacutil.exe.config which was based on .NET 1.1. That was quite old. There was no gacutil.exe in there. However, I was able to run gacuitl from VS2008 command prompt.

Where could the file be? L

Lastly, I found out gacutil was located in -- J

C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin.

This folder contains other assemblies like sn.exe.

The changed Install.bat

REM – Deploying WebPart


 

@SET GACUTIL="C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\GacUtil.exe"


 

Echo Uninstalling the DLL from GAC

%GACUTIL% /u SitePages


 

Echo Installing the DLL in GAC

%GACUTIL% /i "C:\Partha\Devarea\WebPart\bin\Debug\WebPart.dll"


 

Echo Restart IIS Worker Process

Rem IISRESET

Hope this could be handy for others J


 

……. HaPpY CoDinG

Partha (Aurum)