Skip to content

Instantly share code, notes, and snippets.

@vgrem
Last active Dec 17, 2015
Embed
What would you like to do?
CS-Script: reference another C# script
//css_host /version:v3.5 /platform:x64;
//css_dir C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI;
//css_import WebPartManagerExtensions;
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
namespace CSScript4SP
{
class Program
{
static void Main(string[] args)
{
using (var site = new SPSite("http://intranet.contoso.com"))
{
using (var web = site.OpenWeb())
{
web.ForEachWebPartOnPage<Microsoft.SharePoint.WebPartPages.WebPart>("/en/Pages/default.aspx",PrintWebPartInfo);
}
}
}
private static void PrintWebPartInfo(SPWeb web, Microsoft.SharePoint.WebPartPages.WebPart webPart, SPLimitedWebPartManager wpm)
{
Console.WriteLine("{0} {1} {2} {3}", webPart.Title, webPart.GetType().Name, webPart.ZoneIndex, webPart.ZoneID);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment