Sharepoint List Event Handler Types and Example
Welcome Reader,
I have moved to a new blog site, so you can get same content from below new site URL!!
http://dishasharepointworld.blogspot.com/2009/06/sharepoint-list-event-handler-types-and_09.html
Please feel free to post your comments/feedback into new blog, I’ll be more than happy to assistant you.
Sorry for any inconvenience!!
Disha Shah
hey buddy …
excellent article…and very helpful too can u plz tell me wht if i need to place an event handler on say delete button in People and Group section ….
Thanks alot in advance…
Sahil,
Thank you very much for your comment.
Now regarding your question, can you please explain your question in detail?
If I understand correct, then you are looking for adding event handler into link called “Remove Users from group” into People and group sections, please correct me if I am wrong.
As per my understanding there are two alternative ways to achieve same functionality, “People and group” is noting but custom list, so try to find LIST ID of People and group sections and put same LIST ID into event XML file.
Second way would be, add new custom link into “Actions” menu toolbar into “People and group” and call one custom ASPX page on click on new custom link, after custom ASPX page, you can write event handler in same ASP.NET manner. You can add custom link into any toolbar with “custom actions” with SharePoint
Enjoy Coding
Disha
Hi,
I create a workflow (Sharepoint default Approval workflow) in the document library of site collection A, when the document is as of approved i need to trigger my event handler to add this particular document to the Site Collection B.
My problem is workflow works fine but if the document is approved the workflow status will also be changed to Approved, but my event handler doesnto triggers.
Actually i write my code in the ItemUpdated() method. when the workflow status is changed it does not trigger. Also i check the same in ItemUpdating() method too.
Kindly suggest me plzz
Thanx in advance,
here is my thread
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/e2b61937-b941-41aa-8bd9-2a1c1e56672c
Hey,
I think you need to write your event handler code into SharePoint “tasks” list instead of your “document library”, because the workflow status column is not tightly attached to your document library, workflow column is one of the workflow content type which is associated with list, in which we can see status of current workflow steps, from my understanding event handler fires on list when any column values changes. In your case, it’s changing workflow history list/column when your document approved.
Try to trigger your code into tasks list.
One more alternatives as per your requirements: if you will write/create your workflow from visual studio then you can write your logic for moving documents from one site collection to another into “task completed” or “task changed” activities …even if, out of the box workflow fits fine for your requirements.
I hope above information will help you.
Thanks,
Disha Shah
Hi Disha,
Thanx for the reply. Your solution is good and fine. But now i solve it in an different way,
i create an Three-Stage Workflow for the Source Document Library and for that i create a metadata column as WF Status as type Choice, i add three items in the choice as New, Reviewed, Approved. in the evnt handler i check the WF Status column. if the Status column is Approved then the event handler triggers the approved document to the destination site’s destination Document library.
Its working fine
Hi Disha,
Many thanks for the detailed and easy to understand article. I am not greatly experienced with SharePoint API and only just begining to get my self familiar with it.
On this post, I have a question.
If I created an EventHandler let’s say ‘ItemAdded’ on a list (eg Tasks List) on a Sharepoint Site. Now I save this whole site as a template. Now, when I create a new instance of this site, as you are aware that it will inherit all the lists and properties from the template (in our case ‘Tasks List’ also).
My question is – Now will the event handler work (ItemAdded Method) that we wrote earlier? If not then what is the best way around this. If it works .. hurray it saved my day and speed my current project requirements.
Can you please enlighten on this.
Many Thanks,
Hi Prakash,
Thank you very much for the comment. I must say that your question is very good
Question – do event handler work if we do “save site as template”?
YES – It will work, by doing “save site as template” it will carry event handler functionality also into another site in same server where that dll is already in Same Server! Actyally I tried that and it works for me in same sever .
Thanks,
Disha
Hi Disha,
Thank you for getting back to me on this. Excellent, this really means that Event Handlers are a great feature and saves developers time on rewriting codes for a particular list.
Another question that new learners (like me) might find useful is
‘ If I create an EventHandler using the code provided, build the project, sign the assembly, add the .dll to the GAC and add a new project within existing project (type class library) and write all the references to sharepoint list and add the EventReceiver syntax…. Now assuming my code works fine and the event is being captured.
What if I need to update the same project with some new changes (like add a new method or quiet simply change the name of list) then do I just add the changes and click build and the new changes made to the project will be reflected on SharePOint Site or not?’
It would be useful to know how can developers update these files for major or minor changes. Is this straight-forward like I assume or the process quiet tedious?
Can you throw some light on this.
Many Thanks,
Hi Disha,
Also quickly adding to my previous question.
Please spend some time looking at this.
http://saftsack.fs.uni-bayreuth.de/~dun3/archives/getting-started-with-custom-sharepoint-event-receivers/161.html/comment-page-1#comment-334298
You will observe that this method is remarkably simple as there is no need to do anything other than just writing code for the event handler. Although, I could not get this to work can you still look into the credibility of the method. I think it works (although in my case, I dont know why) don’t you think it is easier in terms of achieving functionality I mentioned above for developers.
I can amend my code and simply click deploy and it updates the changes back to browser.
What do you think. Awaiting your reply.
Hi Prakash
If you want to change in your existing event handler let us say add a new method or change list name , then you need to rebuild your solution for new DLL and put DLL into GAC or bin folder(Deploy DLL to proper Place) and just make IISReset.
Yeap I have looked into the link which you provided me, it is really very nice link.
Create SharePoint Empty Project and event handler, Post is good but they did not show contents of MyEventReceiverItemEventReceiver\ItemEventReceiver.xml
May be that’s why it won’t work for you.
Let me know exactly where you stuck with that example, why you feel that it is not working for you?
-Disha Shah
Hi Disha,
Thanks for update on this. First of all, many thanks for offering to help and I really appreciate it. However,the event handler is now working. I did a terrible thing to mistakenly place the code into itemDeleted event where as I should have placed that in itemDeleting event. Then I looked the detailed information you have provided on this post to understand the differences between these events.
This way of working saves developers enormous amount of time to get things done quickly. However, I must convey to everyone going for this approach that even with this, you still have to sometimes deactivate the feature from site settings and then activate is back on for changes to take place (can be time consuming and clunky). But atleast better than doing everything manually.
I am currently doing some more work into this and might get back to you with some possible queries.
Thanks,
Hi Disha,
Your articles are simple and easy to understand and thanks for posting them.
Just wondering if you have any information or any web links that you can share with me to achieve this.
I want to add list item event handlers to a sharepoint site definition – I have a sharepoint site definition which does not pick up the event handlers attached to the lists. How do we put them back on the lists on sharepoint site definition?
How to do this?
Thanks,
Prakash
Thanks for appreciation.
Now I also have some question like Do you get any error when you attach event handlers to list definition? I think in any list definition schema.xml has “eventreceiver” tag, you can add your events there.
If you give me error description if you get, I can give you related and specific links for that.
Still you can refer this link
http://msdn.microsoft.com/en-us/library/bb736146.aspx
Hope this helps
Thanks
Disha Shah
Hi Disha,
Following up on my question and your reply. OK, the easiest way to add event handlers on lists as a part of site definition is to create a Visual Studio project for the site using sharepoint solutions generator 2008. Once, inside the project simply add the event handler by – add new item – eventreceiver feature and add your code to the desired methods. However, make sure you delete previous event handlers on the lists from assembly and template/features folder and also reference from central administration. This will make sure that no event is registered twice. When the site is rolled out the eventhandlers work like a charm..
I see you have recently posted new posts, thanks for that. I will be spending some time to go through those and will get back to you. Keep up the knowledge sharing.
Prakash
Thanks for taking your time to write about how you solved the problem and sharing about that, it really helps someone. I really appreciate that. Thanks for appreciation.
Thanks
Disha Shah
Hi Disha,
I am from a basics sharepoint background, here trying to create a event handler.. just a simple application to take a default document library and achieve the functionality where application validates the Title field and throws an error if contains spaces in its name up on clicking OK button.. can you tell me where do i start from… is it a console application in visual studio? can you provide me the guide lines or steps to develop and deploy this kind of applications.. much appriciate your response.
Thanks,
Naresh
Hi Naresh
There are so many aspects where you can start as a sharepoint. You can create a webpart, EventHandler, BDC, WorkFlows. Open Visual studio , create a small console application or windows form application and start using every object of Sharepoint Object Model. Like create a list, use spgrid, save /delete/add items to list etc..
If you start and you stuck at any place please let me know.
Thanks
Disha Shah
Hello disha I need your help can you plz let me know your id ? or send me a test mail @ admin@bestindiatimes.com
thank you very hope you will consider this.
Hi Admin
I am really glad to assist you, but can you please post your question/concern/issue in the comment section only?
Thanks & Regards
Disha Shah
Hi Disha,
I’m getting the following error message.Can you pls let me know what was the issue.
“Could not load file or assembly ‘EventHandler’ or one of its dependencies. The system cannot find the file specified.”
Hi Venkat
The issue is SharePoint does not find the assembly either in GAC or in bin folder of Web Application.
You need to install Eventhandler DLL to GAC and add that DLL entry as Safe Control in your Web Application web.config file.
Once you add that entry just do the iisreset.
Hope this helps!!!
Thanks & Regards
Disha Shah