项目数应为10但为0

时间:2010-12-14 04:47:07

标签: sharepoint guid splistitem

items.count应该是atlease 10.我有10个子文件夹(Release 1 ..... Release 10),在这个documnent库“Auto Cad”中,每个子文件夹都有一个名为license.txt的文件。嗯 为什么这不返回任何文件?

private void btnGetFileGuid_Click(object sender, EventArgs e)
{ 

using (SPSite site = new SPSite("https://www.abc.com/sites/Software"))
 { 
 using (SPWeb web = site.OpenWeb())
 { 
  SPList spList = web.Lists["Auto Cad"];
  string fileName = "license.txt"; 
  SPQuery query = new SPQuery(); 
  query.Query="<Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='Text'>" + fileName + "</Value></Eq></Where>"; 
  SPListItemCollection items = spList.GetItems(query); 
  if (items.Count > 0) 
   { 
    Guid id = items[0].UniqueId; 
    lblGuid.Text = id.ToString(); 
   } 
  }
 } 
}  

3 个答案:

答案 0 :(得分:0)

query.Query="" + fileName + "";

这条线错了。这应该是CAML查询而不是文件名。

答案 1 :(得分:0)

SPQuery仅搜索特定文件夹 - 以递归方式搜索您需要设置的子文件夹

SPQuery.ViewAttributes = "Scope=\"Recursive\"";

所以你的代码应该是

SPQuery query = new SPQuery(); 
query.ViewAttributes = "Scope=\"Recursive\"";
query.Query=".... REST OF YOUR CODE HERE "

答案 2 :(得分:0)

您需要使用下面提供的问题链接提供的解决方案进行递归调用

我建议使用qry.ViewAttributes =“Scope ='RecursiveAll'”;获取文档和文件夹 query to get all items in a list including items in the sub folders in sharepoint