Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 359
Andrey Avatar asked Jul 25 '12 20:07

Andrey


2 Answers

in C#

Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb =
SPAdministrationWebApplication.Local;
like image 147
RDeVaney Avatar answered Oct 05 '22 09:10

RDeVaney


To expand on the answer from @RDeVaney:

Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb =
    SPAdministrationWebApplication.Local;
string centralAdminUrl = centralWeb.Sites[0].Url;
like image 30
Daniel Flippance Avatar answered Oct 05 '22 07:10

Daniel Flippance