Question

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.

Was it helpful?

Solution

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>";
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top