My current query is below and works adequately enough.

The sharepoint developer is creating a workflow that will look at files in the "Documents" folder, and if it certain flags are set, the workflow will move the file to a subdirectory (e.g. Documents/Maps). Is there a way I can construct the code to make one query but get a list of files from both Documents and Documents/Maps?

Potentially, there could be close to 10 directories. I would like to be able to get the list of files, and surface some of the files to the user based on the metadata.

    private static void ListDocuments(ClientContext clientContext)
        List list = clientContext.Web.Lists.GetByTitle("Documents");

        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml =
        ListItemCollection listItems = list.GetItems(camlQuery);
             items => items
                   item => item["LinkFilename"],
                     item => item["FileRef"],
                     item => item["File_x0020_Size"],
                     item => item["File_x0020_Type"],
                     item => item["Modified"]

First of all, you can include several data operations in you ClientContext query. For example, you can call two or more times ClientContext.Load method, and when call once ExecuteQuery method. Even some logic on server is supported, using conditions scopes (see ConditionalScope) and custom error handling scopes (see ExceptionHandlingScope).

Next, you can set Scope="Recursive" attribute to the View tag, to run through all the descendent folders as well:

    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml =
        @"<View Scope=\"Recursive\">

And another possibility here (if you don't need all the folders), you can use SharePoint Document Sets to classify your data.

  • I'm afraid I don't know Sharepoint, so converting your advice into code is a bit difficult. For example, how would I modify the code above to retrieve / search recursively? – MedicineMan Apr 26 '11 at 23:47
  • Did you read my post? Set camlQuery.ViewAttributes to "Scope=\"Recursive\"". – Andrey Markeev Apr 27 '11 at 6:01
  • I just checked camlQuery. There doesn't seem to be a ViewAttributes property. I suppose this is what confused me. Is there an alternate way of doing this? Could I set the query xml to be <View Scope='Recursive'> <Query/> <RowLimit>100</RowLimit> </View>" – MedicineMan Apr 27 '11 at 9:23
  • Ok, sorry, ViewAttributes are only for server object model for some reason (SPQuery object) :( I will fix my answer. – Andrey Markeev Apr 27 '11 at 11:31
  • Did the provided solution help you? – Andrey Markeev May 2 '11 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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