如何编写 SPQuery 来根据 LinkFieldValue 过滤项目?
我需要根据字段值从 SharePoint 列表中选择单个值。该字段的类型是 LinkFieldValue。我应该如何编写 CAML 查询?
当我选择带有空查询的项目时,我会按预期收到列表中的所有项目。
当我向查询添加约束时,它返回空结果。我尝试按如下方式构建查询:
string.Format("<Where><Eq><FieldRef Name=\"PollInstancePoll\" /><Value "
+"Type=\"Text\">{0}</Value></Eq></Where>",
new LinkFieldValue { NavigateUrl = "/az/Lists/Polls/DispForm.aspx?ID=1",
Text = "example poll" });
这会产生以下查询文本:
<Where><Eq><FieldRef Name="PollInstancePoll" />
<Value Type="Text"><a href="/az/Lists/Polls/DispForm.aspx?ID=1">example poll</a></Value>
</Eq></Where>
I need to select a single value from a SharePoint list based on a field value. The type of the field is LinkFieldValue. How should I write the CAML query?
When I select the items with an empty query, I receive all the items in the list as expected.
When I add constraints to the query, it returns an empty result. I have tried constructing the query as follows:
string.Format("<Where><Eq><FieldRef Name=\"PollInstancePoll\" /><Value "
+"Type=\"Text\">{0}</Value></Eq></Where>",
new LinkFieldValue { NavigateUrl = "/az/Lists/Polls/DispForm.aspx?ID=1",
Text = "example poll" });
which results in the following query text:
<Where><Eq><FieldRef Name="PollInstancePoll" />
<Value Type="Text"><a href="/az/Lists/Polls/DispForm.aspx?ID=1">example poll</a></Value>
</Eq></Where>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经通过以下查询解决了我的问题:
本质上,我只检查链接字段的 URL 部分,并提供用于比较的值
Type="Text"
。请务必记住,SharePoint 始终将数据库中的值存储为服务器相对 URL。I have solved my problem with the following query:
Essentially I am checking only the URL part of the Link field, and providing the value for comparison as
Type="Text"
. It is important to remember that SharePoint stores the values in database always as server-relative URLs.