Search code examples
sharepointsharepoint-2010

How do I obtain Central Administration site url programmatically?


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.


Solution

  • in C#

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