1

In a Documents library, many documents are attached of type word, excel and pdf , i want to find out only PDF Documents using SharePoint server side API? After finding pdf type documents i want to check if they are checked out or not? What will be the possible code to accomplish this?

1

Not sure if you're using 2010 or 2013, but here are a couple of CAML queries you should be able to use for either: 1.) How to write a caml query that filters by .pdf or folders? 2.) https://rmanimaran.wordpress.com/2010/10/19/getfind-all-checked-out-documents-from-a-document-library-using-caml/

Here is some SharePoint 2013 app sample code which gets all pdf files which have been checked out (you can modify the CAML query to also just get all pdf files, checked out or not):

            CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = @"
                <View Scope='RecursiveAll'>
                    <Query>
                        <Where>
                            <And>
                                <Eq>
                                    <FieldRef Name='File_x0020_Type'/>
                                    <Value Type='Text'>pdf</Value>
                                </Eq>
                                <And>
                                <IsNotNull>
                                    <FieldRef Name='CheckoutUser' LookupId='TRUE'/>
                                </IsNotNull>
                                <Neq>
                                    <FieldRef Name='CheckoutUser' LookupId='TRUE'/>
                                    <Value Type='User'>2</Value>
                                </Neq>
                            </And>
                            </And>
                        </Where>
                    </Query>
                    <RowLimit>50</RowLimit>
                </View>";

;

        context.Load(docList.RootFolder, r => r.ServerRelativeUrl);
        context.ExecuteQuery();
        camlQuery.FolderServerRelativeUrl = docList.RootFolder.ServerRelativeUrl + "/";

        ListItemCollection collListItem = docList.GetItems(camlQuery);
        context.Load(collListItem,
            lc => lc.Include(
                i => i.DisplayName,
                i => i.Id));

        context.ExecuteQuery();

        foreach (var item in collListItem)
        {
            MessageBox.Show(String.Format("{0} is checked out!", item.DisplayName));
        }

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

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.