Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to retrive all items that are under a certin folder, in a document library.

this is what i have so far

List DocumentsList = clientContext.Web.Lists.GetByTitle(list);
CamlQuery camlQuery = new CamlQuery();
camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View Scope='Recursive'>
                        <Query>
                            <Where>
                                <eq>
                                    <FieldRef Name='FileDirRef'/>
                                    <Value Type='Text'>
                                        /ecm/Business/Business/Projects/IDECO_P01030000
                                    </Value>
                                </eq>
                            </Where>
                        </Query>
                        <RowLimit Paged='TRUE'> 30 </RowLimit>
                    </View>";
ListItemCollection listItems = DocumentsList.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();

it is definately a caml query problem i am just unsure of how to fix it as yet any ideas would be helpfull

share|improve this question

4 Answers 4

you should also try to load all the folders and files. means

 clientContext.Load(DocumentList);
 clientContext.Load(DocumentList.RootFolder);
 clientContext.Load(DocumentList.RootFolder.Folders);
 clientContext.Load(DocumentList.RootFolder.Files); 
 clientContext.Load(listItems);
 clientContext.ExecuteQuery();

than you can get FolderCollection in Library

 FolderCollection FC = Document.RootFolder.Folders
 Foreach(Folder Fl in FC)
         {
                FileCollection flc = fl.files;
         } 

Hops its help.

share|improve this answer

Have you tried using comparison operator as 'Contains'

    <Contains>
    <FieldRef Name='FileDirRef'/> 
    <Value Type='Text'> 
        /ecm/Business/Business/Projects/IDECO_P01030000 
    </Value> 
    </Contains>
share|improve this answer

Try setting the FolderServerRelativeUrl property of the CamlQuery. See: here

share|improve this answer
up vote 7 down vote accepted

i managed to get it working .

i changed the scope from "Recursive" to "RecursiveAll", RecursiveAll gets all files and all folders under the specidified location.

Caml query was replaced with

    camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"> " +
                    "<Query>" +
                    "<Where>" +
                                "<Eq>" +
                                    "<FieldRef Name=\"FileDirRef\" />" +
                                    "<Value Type=\"Text\">/ecm/Business/Business/Projects/IDECO_P01030000</Value>" +
                                 "</Eq>" +
                    "</Where>" +
                    "</Query>" +
                    "</View>";
share|improve this answer
2  
Sebastien, Your code worked not because you changed the string. It is because you changed the scope from "Recursive" to "RecursiveAll" As RecursiveAll gets all files and all folders under the specidified location. –  user13753 Dec 21 '12 at 7:40
1  
hahah, so i see i asked this question when i was till very new to SharePoint :), thanks for pointing that out –  Sebastien Stettler Dec 24 '12 at 8:00
    
@SebastienStettler : Hey If i want to check multiple conditions by putting <And> in this query how can i achieve that... –  Rahul Gokani May 28 '13 at 4:46
2  
@RahulGokani if you have questions about a specific answer, please use our chat, not comments. Thanx! –  Anders Rask Aug 26 '13 at 12:41
    
this is worked ... <View Scope=\"RecursiveAll\"> .. in last two days i want to retrieve all task items in nested folders in task list and search google : summary task nested folders and so on... ( csom clientcontext ) –  saber tabatabaee yazdi Feb 17 at 18:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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