如何通过编程的方法创建SharePoint提醒
原文出处:
http://www.sharepointology.com/development/how-to-create-alerts-programmatically/
一开始,我将代码写出来,下面我一步步解析:
1. SPAlert newAlert = user.Alerts.Add();
2. newAlert.Title = list.Title;
3. newAlert.AlertType = SPAlertType.List;
4. newAlert.List = list;
5. //newAlert.EventType = SPEventType.Add; <= doesn’t work
6. //use the following codes to set the "eventtypeindex" property
7. //all =0, added = 1, modify = 2, deleted = 3, web discussions = 4
8. newAlert.Properties["eventtypeindex"] = "1";
9. newAlert.AlertFrequency = SPAlertFrequency.Immediate;
10. //passing false to Update method will refrain from sending the alert confirmation mail
11. newAlert.Update(false);
一. 使用SPUser的属性Alerts添加一个新的SPAlert。
1. SPUser user = mySite.Users["domain\user"];
2. SPAlert newAlert = user.Alerts.Add();
二. 如果想绑定到一个SPList。
1. newAlert.AlertType = SPAlertType.List;
2. newAlert.List = list;
三. 如果想绑定到一个具体的SPListitem
1. newAlert.AlertType = SPAlertType.Item;
2. newAlert.Item = item;
四. 下来设定SPEventType,直接对newAlert.EventType赋值会产生一个Exception
SPEventType的取值:
- all = 0
- added = 1
- modify = 2
- deleted = 3
- web discussions = 4
1. //newAlert.EventType = SPEventType.Add;
2. newAlert.Properties["eventtypeindex"] = "1";
五. 设置提醒的频率,马上
1. newAlert.AlertFrequency = SPAlertFrequency.Immediate;
或定时
1. newAlert.AlertFrequency = SPAlertFrequency.Daily;
2. newAlert.AlertTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month,
3. DateTime.Today.Day, 8, 0, 0);
六. 最后调用Update方法,update方法有一个boolean参数,取值为True时马上会发出一份提醒邮件。
newAlert.Update(false);