IAlertNotifyHandler.OnNotification 方法

通知发送,并返回有关警报通知信息后发生。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Function OnNotification ( _
    ahp As SPAlertHandlerParams _
) As Boolean
用法
Dim instance As IAlertNotifyHandler
Dim ahp As SPAlertHandlerParams
Dim returnValue As Boolean

returnValue = instance.OnNotification(ahp)
bool OnNotification(
    SPAlertHandlerParams ahp
)

参数

返回值

类型:System.Boolean
trueSharePoint Foundation会将通知标记为处理 ; 如果否则为false。

备注

创建一个类的继承IAlertNotificationHandler接口,并使用OnNotification方法。这样可以截获传出的通知电子邮件,并对其进行修改。我们可以访问的大多数属性的警报与某些 xml 分析和 SharePoint 对象模型代码,我们可以提取我们需要建立电子邮件的所有信息。使用此信息来构造的 HTML 存根显示根据要求的电子邮件并发送电子邮件使用 SharePoint 的 SendMail 功能。

该示例格式输出尽可能类似于默认通知模板电子邮件,您可以自定义其进一步以满足您的需求。

备注

在项目中包括的Microsoft.SharePointMicrosoft.SharePoint.Utilities命名空间。

示例

    public class Class1:IAlertNotifyHandler
    {
        #region IAlertNotifyHandler Members
        public bool OnNotification(SPAlertHandlerParams ahp)
        {
            try
            {
                SPSite site = new SPSite(ahp.siteUrl+ahp.webUrl);
                SPWeb web = site.OpenWeb();
                SPList list=web.Lists[ahp.a.ListID];
                SPListItem item = list.GetItemById(ahp.eventData[0].itemId) ;
                
                string FullPath=HttpUtility.UrlPathEncode(ahp.siteUrl+"/"+ahp.webUrl+"/"+list.Title+"/"+item.Name);
                string ListPath = HttpUtility.UrlPathEncode(ahp.siteUrl + "/" + ahp.webUrl + "/" + list.Title);
                string webPath=HttpUtility.UrlPathEncode(ahp.siteUrl+"/"+ahp.webUrl);
                
                string build = "";
                 if (ahp.eventData[0].eventType==1)
                 eventType="Added";
                 else if(ahp.eventData[0].eventType==2)
                 eventType="Changed";
                 else if(ahp.eventData[0].eventType==3)
                 eventType="Deleted";

         build = "<style type=\"text/css\">.style1 {font-size: small;       border: 1px solid #000000;"+
         "background-color: #DEE7FE;}.style2 {               border: 1px solid #000000;}</style></head>"+                    
         "<p><strong>"+ item.Name.ToString() +"</strong> has been "+eventType +"</p>"+
         "<table style=\"width: 100%\" class=\"style2\"><tr><td style=\"width: 25%\" class=\"style1\">"+
         "<a href="+ webPath +"/_layouts/mysubs.aspx>Modify my Settings</a></td>"+
                  "<td style=\"width: 25%\" class=\"style1\"> 
                   <a href="+ FullPath +">View "+item.Name+"</a></td>"+
                    "<td style=\"width: 25%\" class=\"style1\"><a href=" + ListPath + ">View " + list.Title + "</a></td>" +
                    "        </tr></table>";
                string subject=list.Title.ToString() ;               
                SPUtility.SendEmail(web,true , false, ahp.headers["to"].ToString(), subject,build);
                return false;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }
        #endregion
    }

另请参阅

引用

IAlertNotifyHandler 接口

IAlertNotifyHandler 成员

Microsoft.SharePoint 命名空间