项目数应为10,但为0

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(); 
   } 
  }
 } 
}  
    
已邀请:
SPQuery仅搜索特定文件夹 - 以递归方式搜索您需要设置的子文件夹 SPQuery.ViewAttributes =“Scope = ”Recursive “”; 所以你的代码应该是
SPQuery query = new SPQuery(); 
query.ViewAttributes = "Scope="Recursive"";
query.Query=".... REST OF YOUR CODE HERE "
    
query.Query="" + fileName + "";
这条线错了。这应该是CAML查询而不是文件名。     
您需要使用下面提供的问题链接提供的解决方案进行递归调用 我建议使用qry.ViewAttributes =“Scope ='RecursiveAll'”;获取文档和文件夹 查询以获取列表中的所有项目,包括sharepoint中子文件夹中的项目     

要回复问题请先登录注册