CAML查询查找参数不存在的记录?
我有一个包含多个字段的共享点列表。看起来,当其中一条记录上的字段留空时,当我使用 CAML 查询查询列表时,该字段上缺少该属性。
是否可以编写一个查询来返回不包含此属性的记录?
示例:
id Employee Title description
-------------------------
1 Jeff Person1
2 Bob Person2
3 Charles Person3
4 Person4
5 Person5
是否有任何方法可以查询此记录以仅返回 id 4 和 5 的记录,因为它们将名称字段留空?
我尝试了以下操作:
System.Text.StringBuilder xmlQuery = new StringBuilder();
xmlQuery.Append("<Query>");
xmlQuery.Append(" <Where>");
xmlQuery.Append(" <IsNull>");
xmlQuery.Append(" <FieldRef Name=\"Employee Title\" />");
xmlQuery.Append(" </IsNull>"); xmlQuery.Append(" </Where>");
xmlQuery.Append("</Query>"); XmlNode query = new XmlDocument();
query.InnerXml = xmlQuery.ToString();
但是这些记录中当然不存在该属性,因此不会返回任何内容
提前致谢!
编辑
将名称
中的任何空格替换为x0020
后,查询将起作用
xmlQuery.Append(" <FieldRef Name=\"Employee_x0020_Title\" />");
I have a sharepoint list which has several fields. It seems that when a field is left blank on one of the records - that attribute is missing on the field when I query the list using a CAML Query.
Is it possible to write a query to return the records which do not contain this attribue?
Example:
id Employee Title description
-------------------------
1 Jeff Person1
2 Bob Person2
3 Charles Person3
4 Person4
5 Person5
Is there any way to query this to only return records with id 4 and 5 because they have left the name field blank?
I tried the following:
System.Text.StringBuilder xmlQuery = new StringBuilder();
xmlQuery.Append("<Query>");
xmlQuery.Append(" <Where>");
xmlQuery.Append(" <IsNull>");
xmlQuery.Append(" <FieldRef Name=\"Employee Title\" />");
xmlQuery.Append(" </IsNull>"); xmlQuery.Append(" </Where>");
xmlQuery.Append("</Query>"); XmlNode query = new XmlDocument();
query.InnerXml = xmlQuery.ToString();
But of course the attribute doesn't exist in those records, so nothing is returned
Thanks in advance!
Edit
The query works after replacing any spaces in the Name
with x0020
xmlQuery.Append(" <FieldRef Name=\"Employee_x0020_Title\" />");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果字段值缺少一个或多个字段,应该不会有任何问题,这是正常现象并且应该可以工作。但是您必须在查询中进行的一项更改是删除外部查询标记,请使用以下查询,您应该可以开始了。
There should not be any issue if a field value is missing one or more fields, it is just normal and should work. But one change you will have to do in the query is to remove the outer query tag please use the below query and you should be good to go.
这是一个不太可能的情况,但是您的“名称”列实际上在列表中名为“标题”吗?
FieldRefs 期望字段的内部名称 AFAIK
This is a longshot, but is your "Name" column actually named "Title" within the list?
FieldRefs expect the internal name of the field AFAIK