The event processing in Sharepoint is EventHandler, and I know it! But I have never done it myself! Perform the following steps Step by step today. All the Notes should be recorded! Learning about Sharepoint is basically from Mr Yang Yonggang's <Microsoft Office SharePoint Server 2007> case study development and Zhang jianyi's <Liang Jian. net sharepoint development practices>! Therefore, the following content is basically the source of the content in the above book.
- Configure EventHandler
- Open the SP Management center and click Application Management> web application general settings)
- Open the web Application general settings page: Web Application [for example: http: // localhost: 5000]: Set it to the address of the web Application to be enabled. If you do not pay attention to this page, you may have enabled EventHandler for other sites! [Haha, I used to encounter], set Backward-Compatible Event Handlers to on
Open the Web Application [http: // localhost: 5000] address you just set, create a document library [KB], and click KB --> Settings --> Advanced Settings: one more item is found: backward compatible event handlers. According to the input box, we need to provide the Assembly, Class
It is best to install WSS Extensions when developing EventHandler! Create a project: MyEventHandlerStudy. Create the EventHandler_DocLibrary class and inherit the IListEventSink interface and paste the code.
-
Using System. IO; using Microsoft. sharePoint; namespace MyEventHandlerStudy {/// <summary> // need to inherit: IListEventSink /// </summary> public class EventHandler_DocLibrary: IListEventSink {# region IListEventSink Members public void OnEvent (SPListEvent listEvent) {// event type [] if (listEvent. type = SPListEventType. insert) {string path = @ "c: \ test. log "; string content = @" user "+ listEvent. userDisplayName + "" In "+ ListEvent. title + "a file \ r \ n" is added to the document library; System. collections. hashtable ht = listEvent. propertiesBefore; foreach (string key in ht. keys) {content + = key + "=" + ht [key] + "\ r \ n";} using (StreamWriter sw = new StreamWriter (path, true )) {sw. write (content) ;}} else if (listEvent. type = SPListEventType. delete) {string path = @ "c: \ test. log "; string content = @" user "+ listEvent. userDisplayName + "" deleted 1 Files! \ R \ n "; System. collections. hashtable htafter = listEvent. propertiesAfter; foreach (string key in htafter. keys) {content + = key + "=" + htafter [key] + "\ r \ n";} using (StreamWriter sw = new StreamWriter (path, true )) {sw. write (content) ;}# endregion }}
Change the project's strong signature (Project property-signature), and the generated path to the bin path under the site (property-> build-> output path )! Generate a project! Use reflector.exe to open the assembly! Enter the Assembly content in the text box above!
For example, Assembly Name: MyEventHandlerStudy, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = c19bb35f3531b88e
Class Name: MyEventHandlerStudy. EventHandler_DocLibrary
Upload a file in the KB document library! Haha go to drive C and check what is in text. log! OH, you have succeeded! [I succeeded, Good Luck]
MOSS Development Training-Event handlerdevelopment Workshop
Technorati tags: sharepoint, EventHandler