Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

-Premchand

share|improve this question

2 Answers 2

WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(this.Page);
int webPartCount = wpm.WebParts.Count;
share|improve this answer
    
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 –  Premchand Peddakotla Jun 26 '13 at 3:56
    
Use SPLimitedWebPartManager.WebParts . This should give you all the weparts in the page. Source: msdn.microsoft.com/en-us/library/… –  Nadeem Yousuf Jun 26 '13 at 5:13

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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