Listing all web parts on a web part page

There are times when you need to see the list of all the web parts on a SharePoint page. It can be done in two ways

First Way:
Browse to the SharePoint page and append the following querystring to the url

e.g. http://yoursite/default.aspx?contents=1

Second Way:
You can write code to achieve the same functionality and list down the web parts on the page.

using(new SPSite("http://mysite/myweb").OpenWeb())

//give relative path of the webpartpage
SPLimitedWebPartManager wm = page.GetLimitedWebPartManager("default.aspx", 
    foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wm.WebParts)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.