项目需要,研究了一下WSS的Alert定制。

定制有两种方法:
(方法1)修改模板文件
默认模板是12"TEMPLATE"XML"alerttemplates.xml,将这个模板复制一份修改,然后用stsadm命令添加模板:
STSADM -o updatealerttemplates -url <http://urlname> -filename <your working copy filename>.

(方法2)写一个类,实现IAlertNotifyHandler接口,然后将这个类的实现配置到自定义的Alert模板中.同样需要用stsadm添加模板.

第一种方法好处是不需要处理具体的发邮件逻辑,但是,因为模板的声明是采用类似CAML的语法,修改起来很是麻烦,并且不能做一些复制的逻辑判断.
第二中方法需要代码来处理发邮件逻辑,控制灵活,但是可能会失去一些系统模板的功能(如项目修改事件通知可以显示出那些字符修改了,那些字符是新添加的).

具体请参考这两篇文章:
http://support.microsoft.com/kb/948321
这篇是wss sdk团队的人写的:
http://blogs.msdn.com/sharepointdeveloperdocs/archive/2007/12/07/customizing-alert-notifications-and-alert-templates-in-windows-sharepoint-services-3-0.aspx

以上两篇文章都采用stsadm添加Alert template,其实,用代码也是可以的:

string templateName="customTemplate1";
//取到服务器的模板即可
SPAlertTemplateCollection ats = new SPAlertTemplateCollection((SPWebService)( base.GetCurrentSPSite().WebApplication.Parent)); 
            
//添加或修改模板
            SPAlertTemplate t = ats[templateName];

            
if( t == null )
                t 
= ats.Add();

            t.Name 
= templateName;
            t.Xml 
= xmlDoc.InnerXml;

            t.Update();

//可以单独设置列表的模板:
SPList list = someList ;
list.AlertTemplate 
= ats[templateName];
//列表试用的模板必须存在与服务器的模板集合中,直接呢为一个模板对象是不可以的.
list.ParentWeb.AllowUnsafeUpdates = true;
list.Update();

 

 

posted on 2008-08-05 10:15  晃晃悠悠  阅读(310)  评论(0编辑  收藏  举报