I have this query which attempts to find this record (which I know exists) in the AllDocs
table within a Sharepoint content database:
The record has these values
DirName: /MYSITE/MYLIST/A_FOLDER
LeafName: B_FOLDER
So the URL looks like: /MYSITE/MYLIST/A_FOLDER/B_FOLDER
Here's the method I'm trying to write:
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;
}
My method always returns false. I can only think of me perhaps using the wrong field names in the CAML query.
Any ideas ?
Thanks.