How to get the program URL of the Central Administration site?

I have some code (console application) running on a SharePoint farm and I need an application to figure out the URL of the Central Administration site for this farm. I remember how some SharePoint APIs did just that, but I can't find it now.

I saw a bunch of hacks that people use for this, for example, a search in the Windows registry, but I need a way through the SharePoint API.

+4
source share
3 answers

in c #

Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb = SPAdministrationWebApplication.Local; 
+9
source

To expand the answer from @RDeVaney:

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

Here is the code from msdn, please consult 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 } 
0
source

All Articles