5
votes

I have some code (console app) running on a SharePoint farm machine, and I need the app to figure out the url of Central Administration site for that farm. I remember seeing some SharePoint API doing exactly that, but I can't find it now.

I've seen a bunch of hacks people are using for that, like looking it up in Windows registry, but I need a way via SharePoint API.

3

3 Answers

10
votes

in C#

Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb =
SPAdministrationWebApplication.Local;
9
votes

To expand on the answer from @RDeVaney:

Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb =
    SPAdministrationWebApplication.Local;
string centralAdminUrl = centralWeb.Sites[0].Url;
0
votes

Here is the code from msdn, please refer if it can answer your question

SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);

foreach (SPWebService webService in webServices)
{
    foreach (SPWebApplication webApp in webService.WebApplications)
    {
        if (!webApp.IsAdministrationWebApplication)
        {
            get the URL here
        }
    }
}