SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to load a list from library containing two files. The following code when tested in CamlBuilder it is returning single row according to the filename selected. But in the program it is returning the whole library regardless of the filename queried

  private Microsoft.SharePoint.Client.List list;
  CamlQuery q = new CamlQuery();
  q.ViewXml = @"<Query>
                                    <FieldRef Name='FileLeafRef' />
                                    <Value Type='File'>"+ fileName + @"</Value>
  var items = list.GetItems(q);
 //cc is the client context
  var item = items[0];
  var fileRef = item["FileRef"].ToString();

Please Help.. Thanks.

share|improve this question
Where do you set the list variable? Could you include that code as well? – RJ Cuthbertson Mar 26 '12 at 15:08
list is just a sharepoint list field declared global to the class. – Flowerking Mar 26 '12 at 15:12
Why the second cc.ExecuteQuery() without loading anything else in between? Perhaps that's throwing it off? – RJ Cuthbertson Mar 26 '12 at 15:17
I don't know why that would affect it, but I don't see anything else odd about your query at first glance. – RJ Cuthbertson Mar 26 '12 at 15:19
well thanks for the input, just now figured out wrapping the query inside <View> tag fixed the issue.. – Flowerking Mar 26 '12 at 15:21
up vote 1 down vote accepted

Wrapping the Query inside "View" tags fixed the issue. Its only returning according to the filename now.

q.ViewXml = @"<View>
                                    <FieldRef Name='FileLeafRef' />
                                    <Value Type='File'>"+ fileName + @"</Value>
share|improve this answer

Your Answer


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.