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 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

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
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
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.