Skip to content

Instantly share code, notes, and snippets.

@vgrem
Last active December 17, 2015 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/5615437 to your computer and use it in GitHub Desktop.
Save vgrem/5615437 to your computer and use it in GitHub Desktop.
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