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 want to retrieve all documents from folder to it's subfolder and so on using client object model.Please help me.

share|improve this question
add comment

4 Answers 4

up vote 2 down vote accepted

I found my solution

  ClientContext clientContext =
        new ClientContext("http://Servername/");
        List sharedDocumentsList = clientContext.Web.Lists.GetByTitle("Shared Documents");
        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml =
            @"<View Scope='Recursive' />";

        ClientOM.ListItemCollection listItems =
            sharedDocumentsList.GetItems(camlQuery);
        clientContext.Load(listItems);
        clientContext.ExecuteQuery();
        foreach (var item in listItems)
        {
        }
share|improve this answer
add comment

If tou would like to retrive only files you should add following line to the VbPatel solution.

camlQuery.ViewXml = @"<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Lookup'>0</Value></Eq></Where></Query></View>"
share|improve this answer
    
Thanks alexander –  Vishal_Sharepoint Mar 27 '12 at 6:41
add comment

You can identify a library's root folder using SPList.Rootfolder property and corresponding subfolders could be accessed using SPList.Rootfolder.SubFolders[index]

Please check this answer for more details and sample code - How to move an item from custom list root location to sub folder programmatically?

share|improve this answer
    
Hi deepu, thax for reply.I want to do this using client object model not object model. And also it's not for only subfolder i want all document form subfolder's subfolder and so on.I think there is some recursive caml query which give all document collection. –  Vishal_Sharepoint Mar 27 '12 at 6:27
add comment
ClientContext clientContext =
new ClientContext("http://Servername/");
List sharedDocumentsList = clientContext.Web.Lists.GetByTitle("Shared Documents");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =
@"<View Scope='Recursive' />";

ClientOM.ListItemCollection listItems =
sharedDocumentsList.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
foreach (var item in listItems)
{
}
share|improve this answer
1  
-1 This appears to be an exact duplicate of the accepted answer. If it isn't, please explain what the differences are, and why they're important. –  Stuart Pegg Sep 25 '12 at 13:45
add comment

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.