13 May 2009

Registing Event Handler on a list/library

for Registering the Event Handler following are the steps to be followed:


  1. Add a Console application project in the Event Handler applcation.

  2. Add the DLL of Event Handler in the GAC.

  3. Now include the following code the console application.

<--CODE-->
static void Main(string[] args)
{
try
{

string AssembleInfo="EventHandlerRegister, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d53fad3f8a2d2037" ;
String ClassName="Akshaya.EventHandlerRegister";
RegisterEvent(
http://registerSite/Sites/site, "MYCustomListName", AssembleInfo, ClassName);
Console.WriteLine("Event Registered Successfully......");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}


Function for registering this Handler
<--CODE-->
private static void RegisterEvent(string SiteUrl, string ListName, string AssemblyInfo, string ClassName)
{
using (SPSite mySite = new SPSite(SiteUrl.Trim()))
{
SPWeb MyWeb = mySite.OpenWeb();
SPList MyList = MyWeb.Lists[ListName];
//include the event handler you have overrided in your handler.ex her is Itemadded
MyList.EventReceivers.Add(SPEventReceiverType.ItemAdded, AssemblyInfo, ClassName);

MyWeb.Close();
}
}

now check the list event firing and incorportating those changes.
Thanks: Akshaya

No comments:

Post a Comment

Thanks for your valuable comments

Rate Now: