In this particular case, I wanted to know what the page was when I was trying to create a new Service Application. If you click the New button in the Ribbon, you'll get a nice flyout menu with a bunch of services to choose from. But where do they go?
Here is a snippet that will get that answer for you:
class Program
{
static void Main(string[] args)
{
ShortDisplay();
}
internal class HeaderColumn
{
public string Title { get; set; }
public int Width { get; set; }
}
static HeaderColumn[] headers = new HeaderColumn[] {
new HeaderColumn{ Title="Application Type", Width=35 },
new HeaderColumn{ Title="Create Application Link URL", Width=45 }
};
static string headerString = string.Empty;
static string lineFormatString = string.Empty;
static List administrationServices = new List();
private static void FormatHeader()
{
for (int i = 0; i < headers.Length; i++)
{
headerString += string.Format("{0,-" + headers[i].Width.ToString() + "}", headers[i].Title);
lineFormatString += "{" + i.ToString() + ",-" + headers[i].Width.ToString() + "}";
}
}
private static void FindAdministrationServices()
{
foreach (SPService service in SPFarm.Local.Services)
{
IServiceAdministration administration = service as IServiceAdministration;
if (administration != null)
{
if (!administrationServices.Contains(service))
{
administrationServices.Add(service);
}
}
}
}
private static List GetAdministrationLinks(IServiceAdministration administration)
{
List administrationLinks = new List();
foreach (Type type in administration.GetApplicationTypes())
{
SPPersistedTypeDescription applicationTypeDescription = administration.GetApplicationTypeDescription(type);
if (applicationTypeDescription != null)
{
SPAdministrationLink createApplicationLink = administration.GetCreateApplicationLink(type);
if ((createApplicationLink != null) && !string.IsNullOrEmpty(createApplicationLink.Url))
{
administrationLinks.Add(createApplicationLink);
}
}
}
return administrationLinks;
}
public static void ShortDisplay()
{
FormatHeader();
FindAdministrationServices();
Console.WriteLine(headerString);
foreach (SPService service in administrationServices)
{
string displayName = (string.IsNullOrEmpty(service.DisplayName) ? service.TypeName : service.DisplayName);
//not very reusable, but good enough for now
if (displayName.Length > 35)
{
int lastDot = displayName.LastIndexOf('.');
if (lastDot >= 0 && displayName.Length > lastDot)
{
displayName = displayName.Substring(lastDot + 1, displayName.Length - lastDot - 1);
}
}
IServiceAdministration administration = service as IServiceAdministration;
List administrationLinks = GetAdministrationLinks(administration);
foreach(SPAdministrationLink createApplicationLink in administrationLinks)
{
Console.WriteLine(lineFormatString, displayName, createApplicationLink.Url);
}
}
}
}
And here is the output:

No comments:
Post a Comment