2

I have a folder in the default "Images" library under my site, called Menu Icons:

/PublishingImages/Menu Icons

I want to retrieve only the images under this folder, and not all images under the root as well, so I thought something like this would work (based on Google searches):

<View>
     <Where>
         <Contains>
             <FieldRef Name="FileRef" />
             <Value>/PublishingImages/Mega Menu</Value>
         </Contains>
     </Where>
</View>

But this brings back all images under /PublishingImages.

If I then view the field values for each, I can see FileRef, /PublishingImages/ for all but one, the one I want located under /Menu Icons.

This looks right?

  • Could you not use <Eq> instead of <Contains>? – BlueBird Aug 15 '13 at 15:58
6

From your code, I think you are using the Client Object Model. There is a property in the Query object FolderServerRelativeUrl which you can use.

If you are using the client object model:

.NET: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.camlquery.folderserverrelativeurl.aspx query.FolderServerRelativeUrl = "/PublishingImages/Mega Menu";

JS: http://msdn.microsoft.com/en-us/library/ee549054(v=office.14).aspx query.set_folderServerRelativeUrl("/PublishingImages/Mega Menu");

Also have a look at this excellent blog about working with Client Object Model Caml Queries in detail: http://karinebosch.wordpress.com/2012/02/03/caml-and-the-client-object-model/

If you are using the Server Object Model, there is a property: SPQuery.Folder http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.folder.aspx

  • using the OM from within C#, so this worked. thank you... – JadedEric Aug 15 '13 at 16:12
1

Try using <View Scope="Recursive"> <Query>..... </View> This should solve your problem.

  • This, for some reason didn't work ?: but thank you. – JadedEric Aug 15 '13 at 16:12
0

Although using the FolderServerRelativeUrl property of the Query object on the client side, or the Folder property of the SPQuery object on the server side as written in the answer by @VardhamanDeshpande should work in your case (I mean, using the OM from C#), there might be cases, when you should filter the results in the CAML-query itself, like when creating a custom view for a document library. For example, we had a requirement to create a view that applies different filter criteria on the root folder level, as on the subfolder level.

We could achieve that via a CAML-query like that:

<Eq>
  <FieldRef Name='FileDirRef' />
  <Value Type='Text'>/YourSite/SubWeb/DocLib/Folder</Value>
</Eq>
  • It is important to ensure that you use the server (and not site!) relative URL of the folder, beginning with a slash. If you use a wrong folder path (that does not exist, or does not belong to a folder within the list you want to filter), the items in the list won't be filtered at all.
  • You should use Eq instead of Contains, as suggested by @BlueBird.
  • Last but not least, you should specify the filter value type as Text (see: <Value Type='Text'>). Without that we had not received any results.

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.