2

I have a folder in document library.

If I get the folder from folder collection of the document library and only query the items inside that folder will it work faster then querying a whole library using the recursive attribute? Just to be clear I only need the items that reside inside that folder.

3

Yes definitely it will be faster, as less items will be retrieved and stored in memory.

Here's sample code,

public void SaveFolderFiles(string fileName, string libraryName, ClientOM.ClientContext clientContext)
    {
        ClientOM.List sharedDocumentsList = clientContext.Web.Lists.GetByTitle(libraryName);
        ClientOM.CamlQuery camlQuery = new ClientOM.CamlQuery();
        camlQuery.FolderServerRelativeUrl = "/Site/Folder/Folder2010/";
        camlQuery.ViewXml =
            @"<View>
            <Query>
              <Where>
                <Eq>
                  <FieldRef Name='FileLeafRef'/>
                  <Value Type='Text'>" + fileName + @"</Value>
                </Eq>
              </Where>
              <RowLimit>1</RowLimit>
            </Query>
          </View>";
        ClientOM.ListItemCollection listItems = sharedDocumentsList.GetItems(camlQuery);
        clientContext.Load(sharedDocumentsList);
        clientContext.Load(listItems);
        clientContext.ExecuteQuery();
        if (listItems.Count == 1)
        {

Source

CamlQuery.FolderServerRelativeUrl property is the key

  • thanks mate , by the way can you post here an example of caml where items from only a particular folder in the doc library are accessed – user8189 May 1 '13 at 15:46
  • Check updated answer. – Muhammad Raja May 1 '13 at 15:52

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.