2

I want to retrieve all documents from folder to it's subfolder and so on using client object model.Please help me.

4 Answers 4

4

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>"
1
  • this is great but it does not retrieve the documents that are under folders and sub folders...
    – Aslan
    Aug 18, 2016 at 17:42
3

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)
        {
        }
0

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?

1
  • 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. Mar 27, 2012 at 6:27
-2
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)
{
}
1
  • 2
    -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.
    – Stu Pegg
    Sep 25, 2012 at 13:45

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.