mercredi 25 mars 2015

CAML Query for getting folder contents based on folder parameters



I have the following folder structure.



Folder1 attr1="cat1"
>> file1 attr2="subcat1"
>> file2 attr2="subcat2"
Folder2 attr1="cat2"
>> file3 attr2="subcat1"
>> file4 attr2="subcat2"
Folder3 attr1="cat1"
>> file5 attr2="subcat1"
>> file6 attr2="subcat2"


I want to get all files(only) which is under folder having field attr1 = cat1, i.e., file1, file2, file5, and file6. Note that attr1 is not available for files. A possible solution is to get all folders, then in a loop, query for files using FolderServerRelativeUrl. But I don't think it is optimal because there will be too much delay for the retrieving the final list, as each ExecuteQuery will take some time. I am using Client Object Model for querying. The CAML query I use only retrieves Folders at Present.



string caml = @"<View Scope='RecursiveAll'>
<Query>
<Where>
<And>
<Eq>
<FieldRef Name='attr1' />
<Value Type='Text'>cat1</Value>
</Eq>
</And>
</Where>
</Query>
</View>";







0 commentaires:

Enregistrer un commentaire