Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

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
add comment

1 Answer 1

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>
                    <Query>
                            <Where> 
                                 <Eq>
                                    <FieldRef Name='FileLeafRef' />
                                    <Value Type='File'>"+ fileName + @"</Value>
                                  </Eq>
                             </Where>
                          </Query>
                     </View>";
share|improve this answer
add comment

Your Answer

 
discard

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.