I have a document library with following structure.

Document Library Name

Now I just want to update the field for FileName_A which is in SubFolderB in FolderB.

I am using following code:

List documentLibrary = clientContext.Web.Lists.GetByTitle(documentLibraryName);
CamlQuery query = new CamlQuery();
query.ViewXml = "<View Scope=\"RecursiveAll\"> " +
"<Query>" +
"<Where>" +
"<And>" +
"<Eq>" +
"<FieldRef Name=\"FSObjType\" />" +
"<Value Type=\"Integer\">1</Value>" +
"</Eq>" +
"<Eq>" +
"<FieldRef Name=\"LinkFilename\"/>" +
"<Value Type=\"Text\">" + FileName+ "</Value>" +
"</Eq>" +
"</And>" +
"</Where>" +
"</Query>" +
var inventionFolders = documentLibrary.GetItems(query);
clientContext.Load(inventionFolders, fs => fs.Include(fi => fi["Title"],
fi => fi["DisplayName"],
fi => fi["FileLeafRef"],
fi => fi[fieldName]
if (inventionFolders.Count == 1)
// Do my stuff

This gives me the context of FileName_A which is in SubFolderA in FolderA.

Can anyone help in building CAML query for this requirement.

I tried with ServerRelativeURL and Recursive instead of RecursiveAll. Still no luck.

1 Answer 1


You can add below condition

        <FieldRef Name=\"FileDirRef\" />
        <Value Type=\"Text\">/site/library/foldername</Value>

And use RecursiveAll to gets all files and all folders under the specified location.

  • I need to get the context particular file under sub folder Aug 9, 2016 at 10:55
  • Then you should use clientContext.get_web().getFileByServerRelativeUrl to retrieve the direct file context Aug 9, 2016 at 10:58
  • I am using c# CSOM Aug 9, 2016 at 11:00
  • Brother it's just a syntax.. If you can't figure out from this hint then how are you going to learn Aug 9, 2016 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.