0

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>
                            <Where> 
                                 <Eq>
                                    <FieldRef Name='FileLeafRef' />
                                    <Value Type='File'>"+ fileName + @"</Value>
                                  </Eq>
                             </Where>
                          </Query>";
  var items = list.GetItems(q);
  cc.Load(items);
 //cc is the client context
  cc.ExecuteQuery();
  var item = items[0];
  cc.ExecuteQuery();
  var fileRef = item["FileRef"].ToString();
...

Please Help.. Thanks.

5
  • Where do you set the list variable? Could you include that code as well? Mar 26, 2012 at 15:08
  • list is just a sharepoint list field declared global to the class.
    – Flowerking
    Mar 26, 2012 at 15:12
  • Why the second cc.ExecuteQuery() without loading anything else in between? Perhaps that's throwing it off? Mar 26, 2012 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. Mar 26, 2012 at 15:19
  • well thanks for the input, just now figured out wrapping the query inside <View> tag fixed the issue..
    – Flowerking
    Mar 26, 2012 at 15:21

1 Answer 1

1

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

q.ViewXml = @"<View>
                    <Query>
                            <Where> 
                                 <Eq>
                                    <FieldRef Name='FileLeafRef' />
                                    <Value Type='File'>"+ fileName + @"</Value>
                                  </Eq>
                             </Where>
                          </Query>
                     </View>";

Your Answer

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

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