当前位置:编程学习 > asp >>

步步为营SharePoint开发学习笔记系列七、SharePoint EventHandler

 

概要

 

     SharePoint的EventHandler主要有Web Level,List Level,List Item Level,Email几种。SharePoint的event handler主要是继承SPWebEventReceiver, SPEmailEventReceiver, SPListEventReceiver和SPItemEventReceiver类去实现其中相应的方法来完成我们的需求。

 

 

 

开发设计

 

注册事件.

 

    /// <summary>

    /// EventHandler

    /// </summary>

    class EventHandler

    {

        private string _assemblyFullName = string.Empty;

        public string AssemblyFullName

        {

            get

            {

                return _assemblyFullName;

            }

        }

        private string _className = string.Empty;

        public string ClassName

        {

            get

            {

                return _className;

            }

        }

        private SPEventReceiverType _eventType;

        private SPEventReceiverType EventType

        {

            get

            {

                return _eventType;

            }

        }

        private string _data = string.Empty;

        public string Data

        {

            get

            {

                return _data;

            }

        }

        private bool _deleteExistingEvents = false;

        public bool DeleteExistingEvents

        {

            get

            {

                return _deleteExistingEvents;

            }

        }

 

        /// <summary>

        /// EventHandler

        /// </summary>

        /// <param name="handlerAssembly"></param>

        /// <param name="handlerClass"></param>

        /// <param name="eventType"></param>

        /// <param name="data"></param>

        /// <param name="deleteExisting"></param>

        public EventHandler(string handlerAssembly, string handlerClass, SPEventReceiverType eventType, string data, bool deleteExisting)

        {

            this._eventType = eventType;

            this._data = data;

            this._assemblyFullName = handlerAssembly;

            this._className = handlerClass;

            this._deleteExistingEvents = deleteExisting;

        }

        /// <summary>

        /// Registers the event handler on the list with the specified name in the specified web.

        /// The function will not throw errors, but will return a string with any error or success description (a log)

        /// </summary>

        /// <param name="web">The SPWeb object of the sharepoint web site containing the list to attach the event handler to</param>

        /// <param name="listName">The name of the list to attach the event to</param>       

        /// <returns>A log of the event assignment</returns>

        public string RegisterEvent(SPWeb web, SPList list)

        {

            StringBuilder sb = new StringBuilder(string.Empty);

            try

            {

                SPEventReceiverDefinition eventReceiver = list.EventReceivers.Add();

                eventReceiver.Name = list.Title + EventType;

                eventReceiver.Type = this.EventType;

                eventReceiver.Assembly = this.AssemblyFullName;

                eventReceiver.Class = this.ClassName;

                eventReceiver.Data = this.Data;

                eventReceiver.Update();

                list.Update(

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,