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
?contents=1

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", 
      System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
 
    foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wm.WebParts)
    {
    }
}

Related Post

Leave a Reply

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