我有这个查询试图在Sharepoint内容数据库的AllDocs
表中找到这条记录(我知道存在):
记录有这些值
DirName: /MYSITE/MYLIST/A_FOLDER
LeafName: B_FOLDER
因此网址如下:/MYSITE/MYLIST/A_FOLDER/B_FOLDER
这是我试图写的方法:
public bool CheckFolderExist(string folderPath)
{
var pathArray = folderPath.Split('/');
string folderName = pathArray.Last(); //The 'LeafName' part...
var temp = pathArray.Take(pathArray.Length - 1);
string folderOnly = string.Join("/", temp); //The 'DirName' part...
CamlQuery cq = new CamlQuery();
string query = @"<View>
<ViewAttributes Scope='RecursiveAll' />
<Query>
<Where>
<And>
<Eq>
<FieldRef Name='FileLeafRef' />
<Value Type='Text'>{0}</Value>
</Eq>
<Eq>
<FieldRef Name='FileDirRef' />
<Value Type='Text'>{1}</Value>
</Eq>
</And>
</Where>
</Query>
</View>";
query = string.Format(query, folderName, folderOnly);
cq.ViewXml = query;
//_accountList is initiated somewhere else for the moment, and it doesn't seem to be the problem for now...
ListItemCollection colFolder = _accountList.GetItems(cq);
_ctx.Load(colFolder);
_ctx.ExecuteQuery();
if (colFolder.Count == 0)
return false;
else
return true;
}
我的方法总是返回false。我只能想到在CAML查询中使用错误的字段名称。
有什么想法吗?
感谢。
答案 0 :(得分:0)
我最终纠正了CAML查询:
string query = @"<View Scope='RecursiveAll'><Query><Where>
<And>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Text'>1</Value>
</Eq>
<Eq>
<FieldRef Name='FileRef' />
<Value Type='Text'>{0}</Value>
</Eq>
</And>
</Where></Query></View>";