2

I want to display the document library's view on the page. To do so, I am using XsltListViewWebpart.

My code is:

XsltListViewWebPart documentView = new XsltListViewWebPart();
documentView.ListId = documentLibrary.ID;
SPView view = documentLibrary.DefaultView;
documentView.Toolbar = "";
StringBuilder xml = new StringBuilder();
xml.Append("<View Name='" + documentLibrary.DefaultView.ID.ToString("B").ToString().ToUpper(CultureInfo.InvariantCulture) + "' TabularView='FALSE' MobileView='TRUE' Type='HTML'  Hidden='TRUE' DisplayName=''  Level='1' BaseViewID='1' ContentTypeID='0x' ImageUrl='/_layouts/images/generic.png'>");

xml.Append("<Query><OrderBy><FieldRef Name='ID'/></OrderBy></Query>");                            

xml.Append("<RowLimit Paged='TRUE'>10</RowLimit>");

xml.Append("<Aggregations Value='Off'/>");

xml.Append("<Toolbar Type='None'/></View>");

documentView.XmlDefinition = xml.ToString();
documentView.AllowClose = true;
documentView.AllowConnect = true;
documentView.AllowEdit = true;
documentView.AllowHide = true;
documentView.AllowMinimize = true;
documentView.AllowZoneChange = true;
documentView.ChromeType = PartChromeType.TitleOnly;
documentView.ID = taskWebPartId;
wpmgr.AddWebPart(documentView, "wpz", 3);

After executing above code web part gets added but the paging is not applied.

To do paging, I have referred this link.

What am I missing?

1 Answer 1

1

As a general rule, Whenever I get stuck in building custom queries (CAML), I start creating a view with the filters, orderings, pagings, ... that I want from the SharePoint UI; Then I will open the view with SharePoint Designer and copy the view query. I suggest you do the same. Just create a view from SharePoint UI and apply paging to it (with whatever number of items in each page you want to be shown), then open the view with SharePoint Designer and copy the CAML query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.