Home > SharePoint, web parts > Listing all web parts on a web part page

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)
{
}
}
Advertisements
Categories: SharePoint, web parts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: