Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

SPSite.HostName property

Gets the name of the server that hosts the site collection.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
public string HostName { get; }

Property value

Type: System.String
A string that contains the name of the host.

When used in conjunction with an SPSite constructor, the HostName property contains a different value depending on the URL that is passed to the constructor. For example, if "http://" + System.Environment.MachineName is passed as the URL, the HostName property contains the name of the computer that is running SharePoint Foundation, but if http://localhost is passed as the URL, then the property contains "localhost".

The following code example displays the host name for the current site collection.

SPSite oSiteCollection = SPContext.Current.Site;
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.