Elencare le Web Parts della pagina (SharePoint)
Un esempio di console application che elenca le web parts contenute in una pagina SharePoint.
C#
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
namespace Sgart.Test
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
SPLimitedWebPartManager wpm =
web.GetLimitedWebPartManager(
"/Default.aspx"
, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared
);
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpm.WebParts)
{
bool spWebpart = wp is Microsoft.SharePoint.WebPartPages.WebPart;
Console.WriteLine(
string.Format("Title: {0} - Zone: {1} - Hidden: {2} - SP WebPart: {3}"
, wp.Title
, wp.ZoneIndex
, wp.Hidden
, spWebpart
));
}
}
}
}
}
}