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
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 specifyingScope
property, in our case scope option is set toShow 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:
- Open List View form page in SPD (AllItems.aspx for a default view)
- Replace
Query
element with the following one:
<Query><Where><Contains><FieldRef Name='FileDirRef'/><Value Type='Lookup'>Orders</Value></Contains></Where></Query>
- 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.
-
-
1Open 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
-
1I 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
-
1