Monday, 7 March 2011

Create Event Handler in SharePoint with Visual Studio 2010

Working with the new Visual Studio 2010 has become so easy that even I can write my own event handlers within no time. Traditionally you'll go thru alot of pain of writing classes, creating features, and then deploying and activation of those features.

here you go in simple steps:

first create new project, by selecting the SharePoint Event Receiver project type.


Enter the site for debugging your code and select deploy as a farm solution



Select the List Item Events type, for Announcements (e.g.) for an item is being deleted


Write your code to handle whatever you want to achieve.


You can build the project, or just simply deploy it to your site if you are sure there are no errors.



Now sit back and relax Visual Studio 2010 will do all the work for you, and deploy the project into correct areas and do whatever is required to be done such as snk, .wsp, web.config, feature activation etc etc.


Now the moment of truth, i'll try to delete an announcement from my site 


and there you go the code has worked, (i don't know how hahaha)





if you notice in your project you had an xml file Elements.xml it has a ListTemplateID="104", here is the list of all id(s) which you might need.

100   Generic list
101   Document library
102   Survey
103   Links list
104   Announcements list
105   Contacts list
106   Events list
107   Tasks list
108   Discussion board
109   Picture library
110   Data sources
111   Site template gallery
112   User Information list
113   Web Part gallery
114   List template gallery
115   XML Form library
116   Master pages gallery
117   No-Code Workflows
118   Custom Workflow Process
119   Wiki Page library
120   Custom grid for a list
130   Data Connection library
140   Workflow History
150   Gantt Tasks list
200   Meeting Series list
201   Meeting Agenda list
202   Meeting Attendees list
204   Meeting Decisions list
207   Meeting Objectives list
210   Meeting text box
211   Meeting Things To Bring list
212   Meeting Workspace Pages list
301   Blog Posts list
302   Blog Comments list
303   Blog Categories list
1100   Issue tracking
1200   Administrator tasks list

No comments:

Post a Comment