We have a document library on our Intranet where documents are stored. The document library also has 2 folders with broken inheritance. I want to loop through all the documents in the document library, including documents in the folders.
This is my code where I try to retrieve all documents with a given content type.
private void IterateItems(SPList list, string contentTypeId)
{
var query = new SPQuery { Query = GetItemsByContentType(contentTypeId) };
var itemCollection = list.GetItems(query);
......
}
private static string GetItemsByContentType(string contentTypeId)
{
return "</Where>" +
"<BeginsWith>" +
"<FieldRef Name='contentTypeId' />" +
"<Value Type='contentTypeId'>" + contentTypeId + "</Value>" +
"</BeginsWith>" +
"</Where>" +
"<QueryOptions>" +
"<ViewAttributes Scope='RecursiveAll' />" +
"</QueryOptions>";
}
The problem is that when this code is executed it does not return the documents that are inside folders. It only returns documents at the top level in the document library. I have executed the CAML query inside a tool, CAML designer, and that returned all documents including those in the folders.
So, now I am wondering why the same query is not returning the desired result when run with server object model.
I run this code as an administrator, so permissions should not be the issue. Any tips or ideas?