2014-02-21 56 views
0

是否可以從sharepoint獲取一個合適的文件而不是在onlce獲取所有文件?查詢從sharepoint獲取文件URL

在以下查詢時我queryNode爲空我得到的所有文件,但queryNode被評論查詢我沒有得到任何文件。

這裏缺少什麼?

 XmlDocument xmlDoc = new XmlDocument();   
     XmlNode queryNode = xmlDoc.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "Query", "")); 

     //queryNode.InnerXml = "<Where>" + 
     //     " <Eq>" + 
     //     "  <FieldRef Name='FileLeafRef'></FieldRef>" + 
     //     "  <Value Type='File'>" + SomeFileName + "</Value>" + 
     //     " </Eq>" + 
     //     "</Where>"; 

     queryNode.InnerText = ""; 

     XmlDocument xmlDoc1 = new XmlDocument(); 
     XmlNode viewNode = xmlDoc.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", ""));    
     viewNode.InnerXml = ""; 

     XmlDocument xmlDoc2 = new XmlDocument(); 
     XmlNode optionsNode = xmlDoc.AppendChild(xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "")); 
     optionsNode.InnerText = ""; 

     XmlNode nodeListItems = wsList.GetListItems("Documents", 
                "", 
                queryNode, 
                viewNode, 
                "1", 
                optionsNode, 
                null); 

回答

0

這將只檢索列表中文件名爲「文件名」的所有項目。

var list = web.Lists["ListTitle"]; 
var fileQuery = new SPQuery(); 
fileQuery .ViewAttributes = "Scope=\"Recursive\""; 
string strQuery = "<Where>" + 
       "<Eq>" + 
        "<FieldRef Name=\"FileLeafRef\"/>" + 
        "<Value Type=\"Text\">" + fileName + "</Value>" + 
       "</Eq>" + 
       "</Where>"; 
fileQuery .Query = strQuery ; 
SPListItemCollection collListItems = list.GetItems(fileQuery); 
+0

我不能用你已經實現的方式var fileQuery = new SPQuery();' – PawanS