1

This is the query I use to get only Powerpoint files from a list:

        Guid id = new Guid(reportLibrary); // ID for the Report library. Needs to be configured at the beginning of the class.
        List sharedDocumentsList = clientContext.Web.Lists.GetById(id);
        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = "<Where><Eq><FieldRef Name='FileExtension'><Value Type='text'>ppt</Value></FieldRef></Eq></Where>";
        ListItemCollection listItems = sharedDocumentsList.GetItems(camlQuery);
        clientContext.Load(sharedDocumentsList);
        clientContext.ExecuteQuery();

I got the query from this question: Selecting only PowerPoint files in a CAML query Sadly, the query does not do what I would expect. It still returns all the files in the list, which results in a crash further down, since the programm I wrote only expects Powerpoint files. Am I doing something wrong? Do I have to execute the query differently?

  • You are missing <View><Query> around your CAML (also add </Query></View> at the end – Robert Lindgren Oct 12 '16 at 11:49
0

You are missing <View> and <Query> tags in ViewXml. Your ViewXml will be like:

camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='FileExtension'><Value Type='Text'>ppt</Value></FieldRef></Eq></Where><Query><View>";
0

I would use DocIcon to filter results, make sure to support both ppt and pptx file formats, and use some value for RowLimit.

<View>
 <Query>
   <Where>
      <Or>
         <Eq>
            <FieldRef Name='DocIcon' />
            <Value Type='Computed'>pptx</Value>
         </Eq>
         <Eq>
            <FieldRef Name='DocIcon' />
            <Value Type='Computed'>ppt</Value>
         </Eq>
      </Or>
   </Where>
 </Query>
 <RowLimit>2000</RowLimit>
</View>

See also:

How to: Retrieve List Items

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.