3

I am trying to fetch the contents of Document Library using paging. For this, I am skipping the resources using ListItemCollectionPosition and getting maximum resources using <RowLimit> in CamlQuery. While everything works fine when OrderBy is not included, Skip doesn't work when I add OrderBy in CamlQuery. I am using below code to achieve the same:

var newObjClientContext = this.GetSharePointClientContext(accessToken, fullUri);
WebCollection collWeb = newObjClientContext.Web.GetSubwebsForCurrentUser(new SubwebQuery());
var documentLibrary = newObjClientContext.Web.Lists.GetById(docID);

ListItemCollectionPosition itemPosition = new ListItemCollectionPosition();
                        itemPosition.PagingInfo = string.Format("Paged=TRUE&p_ID={0}", iSkip);   //Skip thingy doesn't work with Order By

ListItemCollection ltitems = null;

string vquery = @"<View >
                <Query>
                    <Where> 
                        <Or> 
                            <Eq>
                                <FieldRef Name='FSObjType' /> 
                                <Value Type='Lookup'>1</Value>
                            </Eq> 
                            <Eq>
                                <FieldRef Name='FSObjType' /> 
                                <Value Type='Lookup'>0</Value>
                            </Eq> 
                            </Or> 
                        </Where>
                        <OrderBy><FieldRef Name='FileLeafRef' Ascending='TRUE'></FieldRef></OrderBy>                                        
                    </Query>
                    <RowLimit>" + recCount + @"</RowLimit>
                    </View>";

CamlQuery camlQuery = new CamlQuery();
camlQuery.ListItemCollectionPosition = itemPosition;  //This is ignored.
camlQuery.ViewXml = vquery;
ltitems = documentLibrary.GetItems(camlQuery);
newObjClientContext.Load(documentLibrary);
newObjClientContext.Load(ltitems, lists => lists.IncludeWithDefaultProperties(l => l.ParentList));

newObjClientContext.ExecuteQuery();

How can I implement paging using above code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.