Share via

Webs.GetWebCollection Method

Returns the titles and URLs of all sites directly beneath the current site.

Web Service: WebsWeb Reference: http://<Site>/_vti_bin/Webs.asmx


<SoapDocumentMethodAttribute("", RequestNamespace:="", ResponseNamespace:="", Use:=SoapBindingUse.Literal, ParameterStyle:=SoapParameterStyle.Wrapped)> _
Public Function GetWebCollection As XmlNode

Dim instance As Webs
Dim returnValue As XmlNode

returnValue = instance.GetWebCollection
[SoapDocumentMethodAttribute("", RequestNamespace="", ResponseNamespace="", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public XmlNode GetWebCollection ()

Return Value

An XML fragment in the following form that can be assigned to a System.Xml.XmlNode object.

<Webs xmlns="">
   <Web Title="Subsite1_Name" Url="http://Server_Name/[sites]/
      [Site_Name]/[Subsite1]" />
   <Web Title="Subsite2_Name" Url="http://Server_Name/[sites]/
      [Site_Name]/[Subsite2]" />


The following code example displays the titles of all sites directly under the current site. This example requires that a using (Visual C#) or Imports (Visual Basic) directive be included for the System.Xml namespace.

Dim websService As New Web_Reference_Folder_Name.Webs()
websService.Credentials = System.Net.CredentialCache.DefaultCredentials

Dim strMessage As String = ""

Dim myNode As XmlNode = websService.GetWebCollection()

Dim nodes As XmlNodeList = myNode.SelectNodes("*")

Dim node As XmlNode

For Each node In  nodes

    strMessage = strMessage + node.Attributes("Title").Value + ControlChars.Lf

Next node

Web_Reference_Folder_Name.Webs websService = new Web_Reference_Folder_Name.Webs();
websService.Credentials= System.Net.CredentialCache.DefaultCredentials;

string strMessage = "";

XmlNode myNode = websService.GetWebCollection();

XmlNodeList nodes = myNode.SelectNodes("*");

foreach (XmlNode node in nodes)
    strMessage = strMessage + node.Attributes["Title"].Value + "\n";


See Also


Webs Class
Webs Members
Webs Web Service