Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
Web Services
Webs Web Service
Webs Class
Webs Methods
 GetWebCollection Method

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
Webs.GetWebCollection Method (Webs)
Returns the titles and URLs of all sites directly beneath the current site.

Web Service: WebsWeb Reference: http://<Site>/_vti_bin/Webs.asmx
Visual Basic (Declaration)
<SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/GetWebCollection", RequestNamespace:="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace:="http://schemas.microsoft.com/sharepoint/soap/", Use:=SoapBindingUse.Literal, ParameterStyle:=SoapParameterStyle.Wrapped)> _
Public Function GetWebCollection As XmlNode
Visual Basic (Usage)
Dim instance As Webs
Dim returnValue As XmlNode

returnValue = instance.GetWebCollection
C#
[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/GetWebCollection", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", 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.
Xml
<Webs xmlns="http://schemas.microsoft.com/sharepoint/soap/">
   <Web Title="Subsite1_Name" Url="http://Server_Name/[sites]/
      [Site_Name]/[Subsite1]" />
   <Web Title="Subsite2_Name" Url="http://Server_Name/[sites]/
      [Site_Name]/[Subsite2]" />
</Webs>

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.

Visual Basic
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

MessageBox.Show(strMessage)
C#
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";
}

MessageBox.Show(strMessage);
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Permissions      ErikE   |   Edit   |   Show History

Can only called by users that have Contribute permission on the current site, others will get 401: Not Authorized.

Tags What's this?: Add a tag
Flag as ContentBug
Permissions      Frogmancomethagain   |   Edit   |   Show History
In fact you have to be a site collection administrator for this call to work!!!!!!!!!???????????
Tags What's this?: Add a tag
Flag as ContentBug
Permissions      Dor Rotman   |   Edit   |   Show History
You don't have to be an admin.
You can add the "Browse Directories" permission to the permission level associated with the user.

See this post by Andy Burns:
http://www.novolocus.com/2008/07/03/browse-directories-and-webs-getwebcollection-strangeness/
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker