0

I have gotten a big document library. I must show only documents which are in specific folder. How could I show these documents? I have got many folders, but I want to show only the content of one of them.

1 Answer 1

3

Using the following CAML query:

<Query>
   <Where>
      <Contains>
         <FieldRef Name='FileDirRef'/><Value Type='Lookup'>FolderName</Value>
      </Contains>
    </Where>
</Query>

and CAML query options:

<QueryOptions>
   <ViewAttributes Scope='RecursiveAll' />
   <OptimizeFor>FolderUrls</OptimizeFor>
</QueryOptions>

you could specify to retrieve only items from a specific folder named FolderName

QueryOptions element is used for specifying Scope property, in our case scope option is set to Show all files and all subfolders of all folders

How to customize CAML of a List View via SharePoint Designer (SPD)

Let's say we need to display items from a folder named Orders

Steps:

  1. Open List View form page in SPD (AllItems.aspx for a default view)
  2. Replace Query element with the following one:
    <Query><Where><Contains><FieldRef Name='FileDirRef'/><Value Type='Lookup'>Orders</Value></Contains></Where></Query>
  3. Insert the following element after Query element: <QueryOptions><ViewAttributes Scope='RecursiveAll'/><OptimizeFor>FolderUrls</OptimizeFor></QueryOptions>

That's it.

Update

In SharePoint 2013 instead of step 3, specify attribute Scope='RecursiveAll' for a View element.

10
  • And how get Scope folder View in Sharepoint 2013 ?
    – Grzegorz Z
    Jul 23, 2014 at 0:25
  • 1
    Open the form page where list view resides, for example default view page for a Documents library is located here: /Shared Documents/Forms/AllItems.aspx. Find the List View web part declaration and then just follow the steps provided in the answer. Jul 23, 2014 at 7:08
  • 1
    I confirm that it does not work as expected in SharePoint 2013 since, it seems, QueryOptions does not affect in XLV. The solution, instead of inserting QueryOptions element (step 3), update View element by specifying attribute Scope="RecursiveAll" Jul 23, 2014 at 13:38
  • 1
    The answer has been updated. Jul 23, 2014 at 13:40
  • 1
    Worked perfectly with SPD 2013
    – George
    Feb 15, 2019 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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