문제

Is there an easy way to get just the web application URL in SharePoint, for example, SPWEbApplication has the following property spwebapplication.sites that would return URL's of all the site collections, but not of the root URL that they all contain. So I could return this:

http://thiswebapplication:8001/thissitecollection

but not this:

http://thiswebapplication:8001

Is there an easy way to get http://thiswebapplication without any parsing, using the SharePoint or built in ASP.NET objects?

도움이 되었습니까?

해결책

Remember that SharePoint web applications can have multiple URLs since they can be extended onto different IIS websites e.g. http://authoring.site.com and http://www.site.com.

If you're looking to get the URL for the default zone (either with a web app which has been extended or not), you can use:

webApp.GetResponseUri(SPUrlZone.Default);

다른 팁

From the SPWebApplication object you have access to AlternateURLs which will provide the collection of URLs as specified in the Alternate Access Mappings.

SPSite.Url

This is also easily accessed by PowerShell;

$sites = Get-SPSite | Where-Object {$_.Url -like "*portal*"}
 foreach ($site in $sites) {
  Write-Host "Site is SPSite Url=$site"
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top