Use of SharePoint EventHandler!

Source: Internet
Author: User

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.

  1. Configure EventHandler
    1. Open the SP Management center and click Application Management> web application general settings)
    2. 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
  2. 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

  3. 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.

    1. 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.