0

Programmatically - How do I get to the listview web part associated with a list or library. I want to customize it and add it to a web page page in SharePoint 2013. I don't see it in the web part gallery.

2 Answers 2

1

Programmatically, you don't go and get the web part associated with a list. You add a XsltListViewWebPart to a page, and set its associated list to your list's ID.

For example (from this answer on this site) :

var documentsWP = new XsltListViewWebPart();
documentsWP.ListId = documentsList.ID
wpm.AddWebPart(documentsWP, "Left", 0);
0

By default the view pages reside below the list. So the URL format will be like

http://webapp/site/lists/listname/allitems.aspx

You can get list of views using SPList.Views property. To get the view URL you can use Url property.

Once you have the URL you can open the file as a SPFile object. Then you can use SPLimitedWebPartManager to get the webparts on that page.

2
  • I meant listview web part, not page. It was a typo. Commented Mar 26, 2015 at 0:56
  • @KyleJohnson I have updated my answer. Commented Mar 26, 2015 at 1:01

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.