![](/img/trans.png)
[英]Sharepoint Web Services Error GetListItems in Lists.asmx
[英]Search for a Document by its Name using SharePoint Lists.asmx GetListItems
這是我的代碼:
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"<Where><Lt>");
sb.AppendLine(@"<FieldRef Name=""FileRef"" /><Value Type=""Text"">momo.txt</Value>");
sb.AppendLine(@"</Lt></Where>");
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
ndQuery.InnerXml = sb.ToString();
XmlNode resultsElement1 = listsProxy.GetListItems("Documents", "", ndQuery,
null, null, null, "");
但它會返回所有文件任何想法我在這里做錯了什么?
謝謝。
目前,您的查詢是針對名稱值小於momo.text
而不是等於它的項目。 因此將Lt
更改為Eq
。
FileRef
字段包含文檔的服務器相關 URL,類似於“ /Subsite/Lists/ListName/DocumentName
”。 如果您只提供文件名(例如mono.txt
),則Lt
或Eq
都不起作用。
要解決此問題,您可以嘗試:
Eq
與服務器相關的 URL 一起使用,而不是文件名。sb.AppendLine(@"<Where><Eq>"); sb.AppendLine(@"<FieldRef Name='FileRef' /><Value Type='Text'>/SubSite/Lists/Documents/momo.txt</Value>"); sb.AppendLine(@"</Eq></Where>");
<Contains>
運算符(CAML 沒有 < EndsWith>
運算符)。sb.AppendLine(@"<Where><Contains>"); sb.AppendLine(@"<FieldRef Name='FileRef' /><Value Type='Text'>/momo.txt</Value>"); sb.AppendLine(@"</Contains></Where>");
然后循環返回的結果,並刪除不以“ /mono.txt
”結尾的項目。
此外,如果您關心沒有擴展名的文檔名稱,您可以使用BaseName
而不是FileRef
字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.