使用“Membership Type=”CurrentUserGroups””的 CAML 查询没有返回结果
我有以下 CAML 查询来以编程方式过滤列表:
当我在 U2U CAML 查询生成器中执行完全相同的查询(在同一帐户下运行)时,我会得到过滤后的用户、组和日期。 当在代码中应用完全相同的过滤器时,组不会出现在结果中。
组过滤器 (CurrentGroups) 不返回任何结果的原因可能是什么?
应用过滤器的代码是:
SPListItemCollection items = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(theSiteName))
{
using (SPWeb elevatedWeb = elevatedSite.OpenWeb())
{
SPList alertList = elevatedWeb.Lists[theListName];
SPQuery query = new SPQuery();
query.Query = "<Where><And><Geq><FieldRef Name='notificationExpires' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2011-03-30T00:00:00Z</Value></Geq> <Or><Membership Type='CurrentUserGroups'><FieldRef Name='notificationTargetRoles'/></Membership><Contains><FieldRef Name='notificationTargetRoles'/><Value Type='User'>BSFLMK\administrator</Value></Contains></Or></And></Where>";
items = alertList.GetItems(query);
}
}
});
I have the following CAML query to programmatically filter a list:
<Query>
<Where>
<And>
<Geq><FieldRef Name='notificationExpires' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2011-03-30T00:00:00Z</Value></Geq>
<Or>
<Membership Type='CurrentUserGroups'><FieldRef Name='notificationTargetRoles'/></Membership>
<Contains><FieldRef Name='notificationTargetRoles'/><Value Type='User'>MyDomain\administrator</Value></Contains>
</Or>
</And>
</Where>
</Query>
When I execute this exact same query (running under the same account) in the U2U CAML Query Builder I get filtered users, groups and dates.
When apply exact the same filter in code, the Groups do not appear in the results.
What can be the reason that the group filter (CurrentGroups) does not return any results?
The code for applying the filter is:
SPListItemCollection items = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(theSiteName))
{
using (SPWeb elevatedWeb = elevatedSite.OpenWeb())
{
SPList alertList = elevatedWeb.Lists[theListName];
SPQuery query = new SPQuery();
query.Query = "<Where><And><Geq><FieldRef Name='notificationExpires' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2011-03-30T00:00:00Z</Value></Geq> <Or><Membership Type='CurrentUserGroups'><FieldRef Name='notificationTargetRoles'/></Membership><Contains><FieldRef Name='notificationTargetRoles'/><Value Type='User'>BSFLMK\administrator</Value></Contains></Or></And></Where>";
items = alertList.GetItems(query);
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,删除“
SPSecurity.RunWithElevatedPrivileges(delegate()
”部分解决了问题It turns out that removing the "
SPSecurity.RunWithElevatedPrivileges(delegate()
" part corrected the problem