items.count应至少为10。我有10个子文件夹(版本1 .....Release 10)在此文档库中使用"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();
}
}
}
} 发布于 2010-12-14 18:08:52
SPQuery仅搜索特定文件夹-要递归搜索子文件夹,您需要设置
SPQuery.ViewAttributes = "Scope=\"Recursive\"";
所以你的代码应该是
SPQuery query = new SPQuery();
query.ViewAttributes = "Scope=\"Recursive\"";
query.Query=".... REST OF YOUR CODE HERE "发布于 2010-12-14 12:53:17
query.Query="" + fileName + "";这条线是错的。这应该是CAML查询,而不是文件名。
发布于 2010-12-14 19:48:50
您需要使用下面提供的问题链接中提供的解决方案进行递归调用
我建议使用qry.ViewAttributes = "Scope='RecursiveAll'";来获取文档和文件夹以及query to get all items in a list including items in the sub folders in sharepoint
https://stackoverflow.com/questions/4435973
复制相似问题