SPVirtualServerCollection Class

NOTE: This API is now obsolete.

Obsolete. Use the SPWebApplicationCollection class instead. (In Windows SharePoint Services 2.0, the SPVirtualServerCollection class represented a collection of SPVirtualServer objects, and is maintained for backward compatibility.)

Inheritance Hierarchy


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


<ObsoleteAttribute("The SPVirtualServerCollection class is deprecated.  Use an SPWebApplicationCollection instead.",  _
    False)> _
<SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel := True)> _
Public NotInheritable Class SPVirtualServerCollection _
    Inherits SPBaseCollection

Dim instance As SPVirtualServerCollection
[ObsoleteAttribute("The SPVirtualServerCollection class is deprecated.  Use an SPWebApplicationCollection instead.", 
[SharePointPermissionAttribute(SecurityAction.Demand, ObjectModel = true)]
public sealed class SPVirtualServerCollection : SPBaseCollection


Use the VirtualServers property of the SPGlobalAdmin class to return all the virtual servers in the deployment of Windows SharePoint Services.

To create an administrative virtual server, use the CreateAdminVirtualServer method of the SPGlobalAdmin class. To extend a virtual server, use one of the ExtendVirtualServer methods of the SPGlobalAdmin class.

Use an indexer to return a single virtual server from the collection. For example, if the collection is assigned to a variable named myVirtualServers, use myVirtualServers[index] in C#, or myVirtualServers(index) in Visual Basic .NET, where index is the index number of the server in the collection.


The following code example iterates through the collection of virtual servers in a deployment and extends virtual servers that have not been extended with Windows SharePoint Services and creates a top-level site for each.

This example assumes the presence of an administrative form digest in the .cs or .vb file. For information about security validation, see Security Validation and Making Posts to Update Data.

[Visual Basic .NET]
Dim globalAdmin As New SPGlobalAdmin()
Dim vServers As SPVirtualServerCollection = globalAdmin.VirtualServers
Dim i As Integer

For i = 0 To vServers.Count - 1

    If vServers(i).State = SPVirtualServerState.NeedExtend Then

        Dim uri As New System.Uri(vServers(i).Url.ToString())


            Dim newSPServer As SPVirtualServer = globalAdmin.ExtendVirtualServer( _
                "Database_Server", _
                "Database_Name" + i.ToString(), _
                Nothing, Nothing, uri, False, "StsAppPool1", False, _
                Nothing, Nothing)

            Dim sites As SPSiteCollection = newSPServer.Sites

            sites.Add(newSPServer.Url.ToString(), "DOMAIN\User_Alias", "Email_Address")

            Catch ex As System.Exception

                Response.Write(ex.Message + ControlChars.Lf + ControlChars.Lf + ex.StackTrace)

        End Try

    End If

Next i
SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
SPVirtualServerCollection vServers = globalAdmin.VirtualServers;

for (int i=0; i < vServers.Count; i++)

    if (vServers[i].State == SPVirtualServerState.NeedExtend)
        System.Uri uri =  new System.Uri(vServers[i].Url.ToString() );

            SPVirtualServer newSPServer = globalAdmin.ExtendVirtualServer(
                "Database_Name" + i.ToString(), 
                null, null, uri, false, "StsAppPool1", false, null, null);

            SPSiteCollection sites = newSPServer.Sites;


        catch (System.Exception ex)
             Response.Write(ex.Message + "\n\n" + ex.StackTrace);

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also


SPVirtualServerCollection Members

Microsoft.SharePoint.Administration Namespace