Share via


SPSiteCollection.Names property

Gets the server-relative URLs of all the SPSite objects in the collection.

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public ReadOnly Property Names As String()
    Get
'Usage
Dim instance As SPSiteCollection
Dim value As String()

value = instance.Names
public string[] Names { get; }

Property value

Type: []
A string array that contains the server-relative URLs of the site collections.

Remarks

If HostHeaderIsSiteName is true for a particular site, this property returns the absolute URL of the site. Otherwise the server-relative URL is returned.

Examples

The following code example displays the number of site collections and the URL of each site collection within a Web application.

Dim webApp As SPWebApplication = New SPSite("http://MySiteCollection").WebApplication
Dim siteCollections As SPSiteCollection = webApp.Sites

Console.WriteLine("Site Count: {0}" + ControlChars.Lf, siteCollections.Count)

Dim siteUrls As String() = siteCollections.Names
Dim url As String

For Each url In  siteUrls
    Console.WriteLine((url + ControlChars.Lf))
Next url 

Console.ReadLine()
SPWebApplication webApp = new SPSite("http://MySiteCollection").WebApplication;
SPSiteCollection siteCollections = webApp.Sites;

Console.WriteLine("Site Count: {0}\n", siteCollections.Count);

string[] siteUrls = siteCollections.Names;

foreach (string url in siteUrls)
    Console.WriteLine(url + "\n");

Console.ReadLine();

See also

Reference

SPSiteCollection class

SPSiteCollection members

Microsoft.SharePoint.Administration namespace