使用“Membership Type=”CurrentUserGroups””的 CAML 查询没有返回结果

发布于 2024-10-28 00:41:50 字数 1755 浏览 1 评论 0原文

我有以下 CAML 查询来以编程方式过滤列表:

; <哪里> <并且>2011-03-30T00:00:00Z<或> <成员资格类型='CurrentUserGroups'><包含><值类型='用户'>MyDomain\administrator

当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不忘初心 2024-11-04 00:41:50

事实证明,删除“SPSecurity.RunWithElevatedPrivileges(delegate()”部分解决了问题

It turns out that removing the "SPSecurity.RunWithElevatedPrivileges(delegate()" part corrected the problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文