簡體   English   中英

使用 SharePoint Lists.asmx GetListItems 按名稱搜索文檔

[英]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 ),則LtEq都不起作用。

要解決此問題,您可以嘗試:

  1. Eq與服務器相關的 URL 一起使用,而不是文件名。
sb.AppendLine(@"<Where><Eq>");  
sb.AppendLine(@"<FieldRef Name='FileRef' /><Value Type='Text'>/SubSite/Lists/Documents/momo.txt</Value>");  
sb.AppendLine(@"</Eq></Where>");
  1. 或者您可以使用<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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM