当发布特定内容类型的页面时触发SPAlert
谁能告诉我如何仅在 MOSS 中发布特定内容类型的页面时触发警报?
要求是在发布网站的页面库中设置警报,以便在有人使用特定内容类型创建页面并发布该页面时发送通知。我已成功触发使用内容类型创建的页面的警报。当使用 SPAlert.Filter
属性中的 CAML 发布页面时,也会单独进行此操作。
但是,当我使用 CAML
组合查询时,警报停止触发任何通知。
有谁知道为什么会发生这种情况?在 SPAlert.Filter
中使用 CAML
的正确方法是什么?
我的代码:
SPUser user = SPContext.Current.Web.CurrentUser;
SPWeb web = SPContext.Current.Web;
SPAlert alert = user.Alerts.Add();
alert.Filter = "<Query><And><Eq><FieldRef Name='ContentType' /><Value Type='Text'>CUSTOM_PAGE_CONTENT_TYPE</Value></Eq><Eq><FieldRef Name='_ModerationStatus' /><Value Type='Integer'>0</Value></Eq></And></Query>";
alert.Title = "Alert Title";
alert.AlertType = SPAlertType.List;
alert.EventType = SPEventType.All;
alert.List = web.Lists["Pages"];
alert.AlertFrequency = SPAlertFrequency.Immediate;
alert.AlwaysNotify = true;
alert.Update(true);
提前致谢, 日子。
Can anyone please let me know how to trigger an alert only when a page of a certain content type is published in MOSS?
The requirement is to set up alerts in a publishing site's pages library to send off notifications when someone created a page using a certain content type and publish the page. I’ve managed to trigger the alert for pages created using the content type. And seperately when the page is published using CAML in the SPAlert.Filter
property.
But when I combine the queries using CAML <And></And>
alerts stop triggering any notifications.
Does anyone know why this is happening? And the correct way to use CAML <And>
in SPAlert.Filter
?
My Code:
SPUser user = SPContext.Current.Web.CurrentUser;
SPWeb web = SPContext.Current.Web;
SPAlert alert = user.Alerts.Add();
alert.Filter = "<Query><And><Eq><FieldRef Name='ContentType' /><Value Type='Text'>CUSTOM_PAGE_CONTENT_TYPE</Value></Eq><Eq><FieldRef Name='_ModerationStatus' /><Value Type='Integer'>0</Value></Eq></And></Query>";
alert.Title = "Alert Title";
alert.AlertType = SPAlertType.List;
alert.EventType = SPEventType.All;
alert.List = web.Lists["Pages"];
alert.AlertFrequency = SPAlertFrequency.Immediate;
alert.AlwaysNotify = true;
alert.Update(true);
Thanks in Advance,
Rizi.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
您需要在 Query 和 And 之间有一个Where 元素。另外,对于 ModerationStatus,请使用 ModStat 类型而不是 Integer。
Try this:
You need a Where element between Query and And. Also, use a type of ModStat instead of Integer for ModerationStatus.
实际上,SPAlert.Filter 属性不应具有
XML 元素。从过滤器 XML 片段中删除它,您应该可以让它正常工作。选中此页上的第二个注释框:
http://msdn.microsoft.com/en-我们/library/bb802961(v=office.12).aspx
Actually, SPAlert.Filter property shouldn't have the
<Where>
XML element. Remove that from the filter XML fragment and you should have it working.Check the second Note box on this page:
http://msdn.microsoft.com/en-us/library/bb802961(v=office.12).aspx