I got a request from someone to provide a way to enlist webparts used in all publishing pages of a publishing site.
After some initial work I came with this solution. This solution takes a oter">
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.Publishing;
using
Microsoft.SharePoint.WebPartPages;
using
System.Web.UI.WebControls.WebParts;
namespace
ListOutWebParts
{
class
Program
{
static
void
Main(
string
[] args)
{
Console.WriteLine(
"This tool will enlist the webparts"
);
String siteURL = args[0];
try
{
using
(SPSite site =
new
SPSite(siteURL))
{
using
(SPWeb web = site.OpenWeb())
{
PublishingWeb webPublish = PublishingWeb.GetPublishingWeb(web);
PublishingPageCollection pages = webPublish.GetPublishingPages();
foreach
(PublishingPage page
in
pages)
{
SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(page.Url, PersonalizationScope.Shared);
SPLimitedWebPartCollection webCollection = manager.WebParts;
if
(webCollection.Count != 0)
{
Console.WriteLine(
"The page "
+ page.Title +
" contains these webparts"
);
"The page "
+ page.Title +
" contains these webparts"
);
&nbsfont-weight:bold;">for
(
int
i = 0; i < webCollection.Count; i++)
{
Console.WriteLine((i + 1).ToString() +
" "
+ webCollection[i].GetType().Name +
" "
+ webCollection[i].Title);
}
}
}
}
}
}
catch
(Exception e)
{
Console.WriteLine(e);
}
}
}
}