我有以下CAML查询以编程方式过滤列表:
<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>
当我在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);
}
}
});
答案 0 :(得分:0)
事实证明,删除“SPSecurity.RunWithElevatedPrivileges(delegate()
”部分可以解决问题