Note: Updated 1st April 2006 for SP2
I needed to create an eventsync in Windows Sharepoint Portal 2.0. This should have been reasonably straight forward, however with the scenario I found myself in it has taken 3 days of research and pondering to get the job done.
This is my environment and I explain after that how I managed to do it.
Dev Machine
XPSP2, VS2005
Dev Server
W2k3, Sharepoint Services 2.0
- First thing was to copy the Microsoft.SharePoint.dll from the Server to the Dev Machine so a reference could be made to it.
- Create a class library and add a reference to the sharepoint dll
Example using C#
using
Microsoft.SharePoint;
namespace iwaszko.com.STS_EventHandler
{
public class BaseEventSync : Microsoft.SharePoint.IListEventSink
{
void IListEventSink.OnEvent(Microsoft.SharePoint.SPListEvent evt)
{
DispEvt(evt);
}
}
}
- Strong name
Because a strong name is needed for the assembly then in VS2003 you would normally had the path to an assemblykey as an assembly attribute:
Such as [assembly: AssemblyKeyFile("Local_Drive:\\DocLibHandler.snk")]
However it is different for VS2005. You need to open the properties of the Project->Signing, tick the sign the assembly check box and add a path to the strong name keyfile.
(you can create a new Strong name key file in this section if required)
- Build your project and the next stage is to add your dll to the servers GAC. You can do this by dragging you dll into the c:\windows\assembly directory
However this is where things started to go wrong !
- Firstly make sure you have dotNet 2.0 installed on the server. Adding a dotNet 2.0 assembly to a machine without it gives and odd and unhelpful error.
(I found a reboot of the server after installing dotNet 2.0 helped as well but this may not be required)
- Normally, to configure Sharepoint Services to handle events with your assembly you just need to enter its information into the document library advanced settings, however there are a few steps you need to watch out for !
a) Because VS2005 creates a dotNet 2.0 assembly and Sharepoint 2.0 is working on dotNet 1.x you cant register your event handler
I didnt want to revert to VS2003 so I tried to see if you could use dotNet 1.x with VS2005 - according to Microsoft you cant !
"Visual Studio 2005 ships with version 2.0 of the .NET Framework. Visual Studio 2005 does not allow you to choose to support version 1.0 or version 1.1 of the .NET Framework. You can only create projects that support version 2.0." Details here
b) Thus I need to make Sharepoint on the Dev server run on dotNet 2.0
1) You must make sure that the Sharepoint 2.0 SP2 upgrade is installed. This will allow Sharepoint to run on dotNet 2.0
2) Open IIS Administrator, open the properties on the Sharepoint Web Site, Choose the ASP.Net Tab, select 2.0.x as the ASP.Net version.
Note: This will temporarily break you sharepoint installation, but dont panic!
If you try to access the site you will recieve the following message: This Windows SharePoint Services virtual server has not been configured for use with ASP.NET 2.0.50727.42. For more information, please refer to Knowledge Base article 894903 at http://go.microsoft.com/fwlink/?LinkId=42660.
2) Because of the different security model in dotNet 2.0 you must run the following On the Sharpoint server [full details here]:
stsadm.exe –o upgrade –forceupgrade –url http://URLOftheVirtualServer
3) Register and install your dotNet 2.0 assembly into the EventHandler section for the Document Library you require. (Information below from Sharepoint SDK)
- On the Virtual Server General Settings page in SharePoint Central Administration, select On in the Event Handlers section to enable use of event handlers on the virtual server.
Note: To implement the handler in a document library, versioning must be enabled on the Document Library Settings page for the library.
- From a view of the document library to which you want to attach the event handler assembly, click Modify settings and columns, and then click Change advanced settings on the page for customizing the document library.
- On the Document Library Advanced Settings page, type the strong name for the assembly in the Assembly Name box. For example,
DocLibHandler, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=0fafac2a0cc92888. You can get the values used in the strong name by right-clicking the DLL of your assembly in the Local_Drive:\WINDOWS\assembly directory and then clicking Properties on the shortcut menu.
- Type the fully qualified, case-sensitive name of the class in the Class Name box, which in this example is
DocLibEventHandler.DocVersionHandler.
- Reset IIS by typing
iisreset at a command prompt.
I can now use VS2005 with dotNet 2.0 dll's handling the events for Sharepoint Services site which is running on dotNet 2.0 - The best of all worlds - its just a shame these things take so long the first time around. So if you need to do something similar I hope this helps.