I need some C# or powershell script where I need to list down all the web parts that are defined inside a page and not inside a web part zone.

I tried with GetLimitedWebPartManager, but that API, will return only the web parts which are defined inside a web part zone.

But I need an logic, which will give me all the web parts which are not created inside a web part zone.


2 Answers 2

WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(this.Page);
int webPartCount = wpm.WebParts.Count;
  • I cannot use WebPartManager as I wont get Page reference, as I am doing a console application. Its not a web application and its a simple console application and I just need to prepare some report Jun 26, 2013 at 3:56
  • Use SPLimitedWebPartManager.WebParts . This should give you all the weparts in the page. Source: msdn.microsoft.com/en-us/library/… Jun 26, 2013 at 5:13

Use the WebPartManager class. Have a look at the sample code. It uses the GetCurrentWebPartManager method.

Your Answer

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

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