Creating & Adding an Event Handler

In this document, we will create an event handler that captures the events of the document library and add an entry in the cell of the document added. We can add an event handler using code or as a feature. In order to write an event handler, we will first create a sharepoint site and create a document library. We will, then, capture the events of the document library.   

b1-1

1         Writing an Event Handler

We will start from the Visual Studio 2005 new project window. In the new project window, select C# Window application, then, class library as encircled in the figure below and name the project “DocLibEventHandler”.

2.jpg

1.1    Adding Reference

The first thing we will do in the class library is to add reference of the name space Microsoft.SharePoint. This is done by right clicking on the References link in the solution explorer and then clicking on “Add Reference…” as encircled in the following figure:  

3.jpg

Clicking on add reference will generate a new pop up window Add Reference. We will select the Windows® SharePoint® Services namespace, as encircled in the figure below, and click on OK. It will add the Windows® SharePoint® Services namespace in our project.

  

4.jpg

We will add the names spaces, encircled red in the figure below, in our project so that we can directly use the classes in that namespace without specifying the complete path.

5.jpg

 

1.2   Changing Class Name

We will again go to the solution explorer and change the name our class from “Class1” to “DocLibEventHandlerClass”. This can be done by clicking on the class name in the solution explorer and right click on the class name. This will open a new window from which we will select Rename and change the class name from “Class1” to “DocLibEventHandlerClass”. As you change the name of the class, a prompt will appear, shown in the figure below, and ask would you like to rename all references to the code element “Class1”? Click on “Yes”

6.jpg

1.3   Inheriting Class

We will inherit our class from the class SPItemEventReceiver. The path to the class SPItemEventReceiver is Microsoft.SharePoint.SPItemeventReceiver. We have already added the namespace Microsoft.SharePoint, therefore, we just writet the name of the class SPItemEventReceiver for inheritance as shown in the figure below:    

5.jpg  

1.4   Capturing Events

 MOSS provides two types of events namely, synchronous and asynchronous. The “…ing” event occurs before the action starts and the “…ed” occurs after the actions ends. “…ing” events occur synchronously while the “…ed” events occur asynchronously.   

8.jpg 

Synchronous events

  • Occur before the event.
  • Block the flow of code execution until your event handler completes.
  • Provide you with the ability to cancel the events resulting in no after event (“…ed”) being fired.

Asynchronous events:

  • Occur after the event.
  • Do not block the flow of code execution in SharePoint

 To capture these events, class SPItemEventReceiver provides different methods, as shown in the right side of the above figure, which can be seen through Object Browser by pressing Alt+Ctrl+j to see the list of the methods by browsing through Microsoft.SharePoint to SPItemEventReceiver.  We will create a simple program for demonstration purpose. The code will override methods ItemAdding, ItemAdded, ItemUpdated and ItemUpdating in the class SPItemEventReceiver.  

1.5   The Code

 The code will run when a new file is added in the document library and also when an existing document is updated. It will add an entry in the list “CEO Docs Access Log” describing the nature of the event and date on which event occurred. The code is as under: 

namespace DocLibEventHandler

{   

public class DocLibEventHandlerClass : SPItemEventReceiver   

{

public override void ItemAdded(SPItemEventProperties properties)       

{           

SPListItem doc = properties.ListItem;

doc[“Comments”] = “Document has been added”;

doc.Update();

}

//you can use following methods as well        

public override void ItemAdding(SPItemEventProperties properties)        {        }        

public override void ItemUpdated(SPItemEventProperties properties)        {        }        

public override void ItemUpdating(SPItemEventProperties properties)        {        } 

} 

1.6   Signing the Assembly

 The next step is of signing the assembly. To do this, you have to move to the properties window of the project. To do this, right click on the project name “DocLibEventHandler” in the solution explorer and click on the properties in the popup menu. This will open the properties window, select the Signing Pane of the properties window and check the “Sign the Assembly” option. Select <New…> from the “Choose a strong name key file:” and give the name that you desired. In our case, we named it “DocLibeventAssembly” as shown in the figure below:  

9.jpg

1.6   Build Project

 We will build by pressing F6 or clicking on Build in the tolls menu and then clicking on Build Solution. Build will generate the file “DocLibEventHandler.dll” in the debug directory.  

1.7   Copying into GAC

 The file DocLibeventHandler.dll can be found in the debug folder whose path is C:\…..\Visual Studio 2005\DocLibEventHandler\DocLibEventHandler\bin\Debug. Depending upon your installation, you can find the file in the debug folder. Copy the file “DocLibeventHandler.dll” from this folder and paste it in the GAC folder which is normally found at C:\WINDOWS\assembly. After copying the file in the GAC, copy the public token key as encircled in the figure below:  

10.jpg

There are many other ways of adding assembly in GAC. 

1.8   Registering the Event Handler

 In order to register the event handler, add a new console project in the solution by right clicking on the solution “DocLibEventHandler” in the solution explorer as shown in the figure below:  

11.jpg

Select a console project in the “Add New Project” window and name it “DocLibRegApp” as shown in the figure below:  

2.jpg

 Add the following code in the main method. 

namespace DocLinRegApp{   

class Program    {       

static void Main(string[] args)        {           

SPSite sp = new SPSite(http://servername&#8221;);           

SPWeb website = sp.OpenWeb();           

SPList DocLib = website.Lists[“DLOne”];            

string assm = “DocLibEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1d6b41a3ed9a92cb”;           

string class = “DocLibEventHandler.DocLibEventHandlerClass”;            

DocLib.EventReceivers.Add(SPEventReceiverType.ItemAdded, assm, class);           

DocLib.EventReceivers.Add(SPEventReceiverType.ItemAdding, assm, class);           

DocLib.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assm, class);            DocLib.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assm, class);       

}   

}

} 

The string assm describes the assembly details that we have added in the GAC and class is the name of our class. Press F5 to run the project. 

1.9   Changes in the Document Library

Open the site and add document in the document library. Comments column will have the value “Document has been added” as shown in the figure below:

13.jpg

78 Comments »

  1. […] event handler, but if you find difficulty in understanding event handler concepts, explore the this link . We will use the feature added in the previous […]

    • Anonymous said

      Very Nice Blog Farhan.

      My Requirment is to create a event handler for sharepoint 2007 custom list and export values from the list to the oracle table.

  2. […] In case you don’t know how to create and deploy event handler, follow this link. […]

  3. hyze said

    hi farhan,

    i have tried the solution, but wondering why in my document library, the comment is not listed? do i need to create that column.

    thanks

  4. farhanfaiz said

    Yup. You need to create comments column.

  5. hyze said

    thanks. One more things. i saw alot of example from the SDK regarding the code sample. is it a same step that i need to use to run the code? i mean using the Console Application?

    Really appreciate your help
    Thanks

  6. hyze said

    why the comments didnt change after i edited. below is my the code. did i missing something?

    namespace DocLibEventHandler
    {
    public class DocLibEventHandlerClass : SPItemEventReceiver
    {
    public override void ItemAdded(SPItemEventProperties properties)
    {

    SPListItem doc = properties.ListItem;

    doc[“Comments”] = “Document has been added”;

    doc.Update();
    }
    public override void ItemUpdated(SPItemEventProperties properties)
    {

    SPListItem doc = properties.ListItem;

    doc[“Comments”] = “Document has been updated”;

    doc.Update();
    }

    }
    }

  7. farhanfaiz said

    hyze,

    Steps are misssing here:

    1- Did you install DLL in GAC?
    2- Restart IIS?

    I believe that most of the time code is fine, its the installation which suffers.
    do let me know.

  8. hyze said

    yes!

    i did all of that, but some reason it not working. but if i take out the ItemUpdated
    method and use only ItemAdded. It’s working fine.

  9. Partha said

    Gr8 solution…thanks

  10. Eduardo Moreno said

    Hi, I’m trying to change the emailreceived method, but for some reason, when I register the event handler, it erases the email… it stays in the folder where sharepoint picks it up, but instead of adding it to the discussion board, it erases it. Here’s my code.
    namespace try
    {
    public class SimpleHandler : SPEmailEventReceiver
    {

    public override void EmailReceived(SPList list, SPEmailMessage emailMessage, string receiverData)
    {

    SPListItem item = list.Items.Add();

    item[“Subject”] = emailMessage.Headers[“Subject”];

    item[“Body”] = emailMessage.HtmlBody;

    item.Update();

    }

    }
    }

    Can anyone help me?

    Thanks in advance.

  11. mari said

    Do you know if it is possible to block the sharepoint code in a ItemAdded eventhandler? I have a event handler that changes the name of the file and move it into another folder.
    I want to show the new file name in the form of edit item, but it shows the old name cause sharepoint doesn’t wait until my event ends.
    thanks.

  12. Farhan Faiz said

    Quick workaround is that try to change the code in the Event Handler.

  13. Dirk said

    Great sample / tutorial…

    But one question. Is it so that the Updated and Updating event are always fired even when the item is created for the first time?

    Greets and thanks for the great post

  14. Farhan Faiz said

    Dirk,

    I don’t think so that Updated and Updating event are fired when the item is created for the first time.

    Regards,

  15. Anil said

    Shall we do the same thing as adding items in the document library and the same time Event handler should trigger to add item to an SPList. Here i mean my Document Library and SPList contains same Fieldnames as for say Document_Name, Document_Url.

  16. Farhan Faiz said

    yes. we can do that.

  17. Anil said

    Hai Farhan,

    I use the following code for an event handler.
    In this i can’t get the Metadata item values when item is created in Document Library this event handler must trigger an event to add particular data (Metadata) to an Coustom List, but here it return only NULL value. , Please go through the below code and get me the help.

    //Checks wheather value is Null or Not
    public string retstring(object obj)
    {
    try
    {
    return obj.ToString();

    }
    catch
    {
    return “NULL”;
    }
    }
    private const string FIELD_DOC_Name = “DocName”;
    public override void ItemAdding(SPItemEventProperties properties)
    {
    try
    {
    SPListItem doc = properties.ListItem;
    SPWeb site = properties.OpenWeb();
    //string dn = site.Lists[properties.ListId].Fields[FIELD_DOC_Name].InternalName;
    SPList TaskList = site.Lists[“DispHomeDocs”];
    SPListItem item = TaskList.Items.Add();
    //also i check with the below code which is commented.
    // item[“DocName”]=retsring(properties.AfterProperties[FIELD_DOC_Name]);
    item[“DocName”] = retstring(doc[“DocName”]);
    item[“DocUrl”] = doc.Url;
    item.Update();
    }
    catch (Exception ex)
    {
    EventLog.WriteEntry(“Error: “, “E1” + ex.ToString());
    }
    }

  18. Farhan Faiz said

    Anil,

    can u try against ItemAdded event handler.

    Do let me know.

  19. Anil said

    Hai Farhan,

    Am sorry to say you, i try on both ItemAdded and ItemAdding. Here is the code as ItenAdding, actually i use this as ItemAdded(). Now also i cant able to get custom column from the document library.

  20. Anil said

    Hai Farhan,

    Now i solve my problem, i use my code in ItemCheckedIn()

    public override void ItemCheckedIn(SPItemEventProperties properties)
    {
    SPListItem docItem = properties.ListItem;
    SPWeb web = properties.ListItem.Web;

    // create a new item in an existing Task List
    SPList TaskList = web.Lists[“DispHomeDocs”];
    SPListItem taskItem = TaskList.Items.Add();

    // update the task using the properties from the document item
    taskItem[“Docname”] = retstring(docItem[“Docname”]);
    taskItem[“DocUrl”] = docItem.File.Url;
    taskItem.Update();
    }

    Thanx for your tips.

  21. Anil said

    Hai Farhan,

    Now i need to add my event handler as above created want to add Document Libraries of Sub Site.

    In my Top Level Site (current site) i had one document library and an custom list. while using this above Event handler i can add item to the custom list, while any Document added or Check In to the Document Library.

    Now i had some sub sites on my above site and also subsites contains document libraries. When i Upload or added or check In any document in the sub site’s Document Library. i need to trigger my event handler and add those item into my custom list..

    Any idea to do it. If can plz help me.

  22. Farhan Faiz said

    Anil,

    Add event handler against the document libraries.

    Do let mw know.

    Regards,

  23. Sameh said

    Dear All,
    is there any way to debug the event code ??
    thanks for help

  24. Saud Siddiqui said

    Hi Farhan,

    Thanks for this great article.
    I have tried your tips. The event handler for ItemAdded is running fine but for the ItemDeleted it is not running. The codes are common for both handler. Any sugestion would be greatly appreciated.
    Thanks.

  25. Farhan Faiz said

    Sameh,

    Tip is that in VS, click on debug and attach process w3wp.exe.

    Do let me know.

  26. banchana said

    I have sharepoint portal server 2003 and microsoft outlook 2003. I have my customers fill in a task request form, an internet application, and submit it. I have it where it gets sent to my outlook as a task. Is there a way that I can send it as a task in sharepoint task list in an unassigned task list area and then once I assign task, it should move to the assigned task list and disappear from the unassigned task list. Any help is appreciated.

  27. rocafort said

    Hello,

    I got interested with the thread.

    Actually I am a beginner in Sharepoint,and I encountered a problem. I have a document library having a content type attached with a workflow. Everytime a I used this content type the workflow initiated. I created Assigned to column in document library list, so that I can figure out to whom this document assigned to. I am thinking that I can get the value from the Task List since all the fields there were created.

    Docs Library -> Add Document -> Task list created because of the workflow -> get the assigned To value in Task -> populate the Value in assigned to Column in Document Library

    How will I do that? Can anyone of you can help me. I saw Anil Code which is I guess sort of the same with my problem. But I cant figured it out well. How will I implement it?

    Thanks in advance.!

  28. Farhan Faiz said

    rocafort,

    write an event handler on item created in task list and this event handler populates “Assigned To” column in document library.

    Do let me know.

    Regards,

  29. Dharnendra said

    Hi,

    I am using some unsigned Project DLL (like Common,etc..) inside my event receiver class library.

    When i am trying to deploy my DLL, its also ask for the deployment of ‘Common’ project DLL at GAC but as the project is referring some unsigned DLL ,i can’ make that project to signed and so enable to put that it’s in GAC.

    Can i get any workaround for the above situation?

    Do it possible that i not require to deploy the DLL to GAC and can work with DLL by placing only it in ‘Application’s Bin’ folder.

    Please provide me your help…its urgent

    Thanks

  30. rocafort said

    Hi Farhan Faiz,

    How supposed to be my code looks like? 😦

    I created one eventhandler and i succesfully the name manmualy on the assigned to column. However, what I need is to get the Assigned to value created in the task list and put it in the assigned to column in library list.

    Please, share to me the codes.

    Thanks.
    -rocafort-

  31. Farhan Faiz said

    rocafort,

    Following psot may help you:

    Event Handler to Synchronize (Populate Data) List / Document Library Columns Form Other Document Library / List Columns

    Do let me know.

    Regards,

  32. rocafort said

    Hello,

    I have created a workflow using SP Designer. The step i ‘ve created is to update the column in the list. It works fine using the content type template to create an entry on the list. However, when I used the Upload functionality, I have encountered an error.

    The file Workflow Document/WordTemplate.doc has been modified by SHAREPOINT\system on 28 Nov 2008 11:23:48 +0800.

    When I go the list, the entry was created and the column was successfully updated.

    Please help me to solve this problem. This is quite urgent.

    Thanks in advance

  33. Avi Kumar said

    Hello

    I need to implement same thing in different manner. I like to implement on form library, which is email enabled. Now I like to create an event handler where it will check the email attachment and transform xml as per infopath form library format using an standard XSLT. I have completed XML transformation, but I not able to understand how do I use this transform code before item add event.

    Can any one of help in writing this code?

    Avi Kumar

  34. satyanarayan said

    hi farhan,
    i tried your code but it is not working,i follow the whole procedure as mentioned in block. below is code.
    can u tell me what mistake i am commiting

    public class DocLibEventHandlerClass : SPItemEventReceiver
    {

    public override void ItemAdded(SPItemEventProperties properties)
    {

    SPListItem doc = properties.ListItem;

    doc[“Comments”] = “Document has been added”;

    doc.Update();
    }

    }

    public class Program
    {
    static void Main(string[] args)
    {

    SPSite sp = new SPSite(“http://192.168.1.230:556”);

    SPWeb website = sp.OpenWeb();

    SPList DocLib = website.Lists[“test”];

    string assm = “DocLibEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cb3e5b8193bf85ad”;

    string class1 = “DocLibEventHandler.DocLibEventHandlerClass”;

    DocLib.EventReceivers.Add(SPEventReceiverType.ItemAdded, assm, class1);

    DocLib.EventReceivers.Add(SPEventReceiverType.ItemAdding, assm, class1);

    DocLib.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assm, class1);
    DocLib.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assm, class1);

    }
    }

    • Farhan Faiz said

      Sorry for late reply.

      I am not sure about URL in the SPSite object. Also, why r u adding handlers against ItemAdding, ItemUpdated and ItemUpdating.

      Do let me know.

  35. satyanarayan said

    i am pretty new in sharepoint, i am just trying to use event handler. Now my problem is solved.
    what do you mean by “why r u adding handlers against ItemAdding, ItemUpdated and ItemUpdating”. can’t we add event handler against these events.please let me know

  36. Farhan Faiz said

    satyanarayan ,

    You can add other event handlers but i fail to find the methods that override them

    Regards,

  37. Biju said

    Hi,

    Am new to SharePoint, I have undergone the training on WSS and MOSS.

    Can anyone please tell me how to Customize the exisitng Task List and Event Handler for Task Lists.

    I want to update the tasklist based on the date and time of start and completion

    Biju

  38. Suraj said

    Hi,

    Nice article… But I have one small query, Here you explained how to add this event handler to my list. Now can you please tell me how to remove the event from that list,
    I have added this eventhandler to one of my lists employee, now i no more need it so how do i remove or deactivate the eventhandler?

  39. Biju said

    Please help

    my requirement is as follows
    1) I need to create eventhandler for the tasklist
    2) the tasks should automatically based on any change in the ending date of its dependent task
    3)In the same way if a new task is added between any two dependent tasks.

  40. Vince said

    Hi,

    I have followed this step by step but using VS2008, When it comes to the final section (running the Program to register the event handler), I press F5 and get:

    “A Project with output type class library cannot be started directly directly.

    In order to debug this project, add an executable projectto this solution which references thr library project. Set the executable project as the startup project”

    Any ideas what I should be doing here? am a relative sharepoint/coding noob so any help is greatly appreciated.

  41. Vince said

    Sorry dude, cancel the previous! Had output in properties set to dll instead of application.

  42. sabi said

    Hi Farhan,

    Thanks for this nice article on event handling for beginners like me.
    I need to create subsite whenever a new project has been added and I need to provide the url of the newly created site to the list’s URL field of the project.

    Please suggest me how I can do this.

    In your example, ItemAdded event works fine but ItemUpdated doesn’t work for me.
    If I associate different events with the same list like ItemAdding, ItemUpdated,…how to represent such events in the Elements.xml ?

    I tried to debug in VS 2005 using attach to process. Can u please provide me
    link to learn about debugging in Sharepoint.

    -Thanks in advance,
    Sabi

  43. sabi said

    Hi Farhan,

    I coded the ItemAdding Event as follows, for creating the site and providing the link of the newly created site in the project list.
    Please Tell me how to make it work.

    public override void ItemAdding(SPItemEventProperties properties)
    {
    //base.ItemAdding(properties);
    SPSite site = new SPSite(“http://esssharepoint20:4444/”);
    SPWeb web = site.OpenWeb();
    SPListItem item = properties.ListItem;//ListItem represents an item or row in a list
    string CurrentSiteTemplate = web.WebTemplate;
    string sitename = properties.AfterProperties[“Title”].ToString();

    try
    {
    web.Webs.Add(sitename, sitename, “New project site added with esssharepoint20:4444”, (UInt32)

    System.Globalization.CultureInfo.CurrentCulture.LCID, CurrentSiteTemplate, false, false);
    string sitelink = “http://esssharepoint20:4444/” + sitename;
    SPFieldUrlValue redirectUrl = new SPFieldUrlValue();
    redirectUrl.Url = sitelink;
    redirectUrl.Description = “project site”;
    properties.AfterProperties[“Project_x0020_Site”] = redirectUrl;
    this.DisableEventFiring();
    item.Update();
    this.EnableEventFiring();
    }
    catch (Exception ex)
    {
    }
    finally
    {
    site.Close();
    web.Dispose();
    }
    }

    -Thanks,
    Sabi

  44. Farhan Faiz said

    I need to create subsite whenever a new project has been added and I need to provide the url of the newly created site to the list’s URL field of the project.

    Any details reagding “New Project”?

    If I associate different events with the same list like ItemAdding, ItemUpdated,…how to represent such events in the Elements.xml ?

    Need to add enteries.

    I tried to debug in VS 2005 using attach to process. Can u please provide me
    link to learn about debugging in Sharepoint.

    You can dubug by attaching process. For excat details, check out video on Channel 9. I forget the exact link 😦

  45. Farhan Faiz said

    Try to add against ItemAdded

  46. sabi said

    Hi,

    I tried using ItemAdded event and then I was using ItemAdding.
    In ItemAdded, the site was be created but in ItemAdding nothing happens.
    Is something wrong with the code for adding a link?
    Whenever, the project manager registers a new project, the site has to be created and link provided.
    How to provide permissions for the newly created site dynamically?

    -Thanks,
    Sabi

  47. Farhan Faiz said

    Sabi,

    “register a new project” ? plzz provide details like add an item in a list or something else?

    Regards,

  48. sabi said

    Hi Farhan,
    Sorry. It is adding a new item in the Project Tasks. The ListTemplate Id I used in the Elements.xml is 150.

    -regs,
    Sabi

  49. sabi said

    Hi Farhan,

    I am able to create the site and hyperlink using ItemAdding Event.
    Thanks for your help.

    -Sabi

  50. sandrar said

    Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

  51. Fabio Agrifoglio said

    Hi, in the example you have to change class variable, the name is reserved :=)
    Fabio

  52. Hartim said

    Thanks, this is great. I have the ItemAdded event modified in one of our libraries using your code.

  53. Deepak Kumar Shrivastava said

    Hi Farhan,

    Thanks for the nice article.

    I am newbie to sharepoint and with the help of your article i have learned to debug evenhandlers.

    I am facing problem at:

    1.Whenever i change something in my code i am replacing dll file in GAC but my changes are not reflecting but debugger is working fine.

    Can you Pl suggest something for it.

    Thanks in advance
    -Deepak

  54. Farhan Faiz said

    did you reset IIS?

  55. DJ said

    Hi, Thanks a lot for this great article.
    Im quite new to sharepoint and Microsoft technologies. I have a doubt. You have mentioned to create a console application for registering the event handler.

    I have a requirement like wheneever i update/Add a document in one document library(based on a dropdown column value ), i need to add/update the same document in another document library automatically.

    So my doubt is we need to run this console application every time ? Then only it will get updated ? Is it possible to do without running the console application ? Or after adding the dll in GAC , it will be updated? Please advice.

    • Farhan Faiz said

      Hi,

      If I have to do that task, I will be using SharePoint Designer Worlflow to copy document from one document library to other. Please do let me know in case further assistance in desired.

      Regards,

  56. Mat said

    Hi,

    Great article. Helps a lot for beginers like me…
    One small doubt(may be silly) , regarding attaching the event handler.

    Do we need to run it the Console application everytime we modify the document libraries? Or it will be attached when we run the console application the first time itself and each time anyitem is added/updated, the events will be fired?
    Thanks a lot.

    • Farhan Faiz said

      Event will be fired automatically once atatched.

  57. Taf said

    Nice and simple, works great 🙂
    Moss is always a great toy to play with.

  58. Valeras said

    HI, great post.
    But I have one little newbie problem..

    Maybe u have some tips how to write event code which will add An Item in my custom task list every time when created item with task type?

    Goal is to have one “AllTasksItems” list from diferent sites.

    Please help.

  59. NEwSPDeveloper said

    Hello,

    i used everything to test my code and it gives me an exception around
    DocLib.EventReceivers.Add(SPEventReceiverType.ItemAdded, assm, class1);

    It says : Not able to load ….

    I wonder why?

    • Farhan Faiz said

      Deatils of the error will help a lot. What i can suggest now is debug the code and attach process (Debug -> attach to Process and process name is “w3wp.exe”. May find something.

  60. badhon said

    can anyone please tell me if we can access two lists at the same time while handling these events. because i need to access another list form the same site for some additional data.

    • badhon said

      for clarity i need to fire the event in one List only. but need some info from some other list as well. please help..
      Thanks!

      • Farhan Faiz said

        You can use SharePoint Object Model to access other list and get required info.

      • badhon said

        yes. it works :). Thanks!

        another question:
        i have put the class library in the GAC. i needed the same functionality in few other lists as well. So, what i did was changed the URL and Lists acoordingly in the console app evertytime and executed it once for every list. But now if i want to remove the Event Handling from one of the lists, what do i do?

      • Farhan Faiz said

        SPList.EventReceivers will give you list of all event receivers.

        http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.eventreceivers.aspx

  61. badhon said

    hi Farhan Faiz,
    sorry for a question which is not an eventhandler type(which is the type of this particular blog)….but i like the way u gave this solution..so just thought i would get a quicker response if i posted my query here…
    my question is…..

    i have a document library (say A) which has a look up field (the value stored in which is the value of “ID” column from another List (say B). now i am running a loop for each SPListItem of A.here for each of SPListItem in A i need to get the value of column “Name” of list B. currently i have done is hard coded the list B’s url and name and travered B(and using the vlue of “ID” got the Value of “Name”by getItemByID). i would be interested to know if it is possible for me to do it withourt hard coding the name and url of B and directly traverse B by any other means. Can we do it using SPFieldLookUp?
    thanks in advance.

    • Farhan Faiz said

      I don’t have exact idea of limitations you are facing. I will really appreciate if you can provide more details that why you need URL?

  62. girija said

    Hi,
    Whats the use of registering event handler, is that mandatory..?

    • Farhan Faiz said

      Yes. If we don’t register, it will not fire.

  63. J0hnSm1th said

    Nice one… Really simple to follow and use was able to crowbar my sutff very neatly into this sort of idea!!!

    Thanks

  64. J0hnSm1th said

    Hi Farhan,

    When you update the eventhandler should you rerun the console application, I ask this as I have been doing this and now when I have an update going through it seems to list 8 comments everytime?

    Any ideas why this might be happening?

    Cheers

    • Farhan Faiz said

      If i remember correctly, we need to rerun.

  65. Deepak said

    We have also same problem, while using ItemAdding and ItemUpdated.
    ItemAdding is working and ItemUpdated or ItemUpdating is not working. Finally we deactivate the feature and retract the solution than once again deploy the solution and activated the feature. Now its working fine.

  66. This website was… how do you say it? Relevant!! Finally I’ve found something that
    helped me. Thank you!

RSS feed for comments on this post · TrackBack URI

Leave a reply to Farhan Faiz Cancel reply