PublishingWeb.GetPublishingWebs method

Returns child PublishingWeb objects immediately below this PublishingWeb object.

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

'Declaration
Public Function GetPublishingWebs As PublishingWebCollection
'Usage
Dim instance As PublishingWeb
Dim returnValue As PublishingWebCollection

returnValue = instance.GetPublishingWebs()

Return value

Type: Microsoft.SharePoint.Publishing.PublishingWebCollection
A PublishingWebCollection collection with all child PublishingWeb objects immediately below this PublishingWeb.

All PublishingWeb instances in this collection should be closed by the caller using the SPWeb.Close method.

This method creates a new PublishingWeb below the root Web site of a PublishingSite.

The SPSite that is passed in should be a site that supports the Publishing feature.

Imports SPSite = Microsoft.SharePoint.SPSite
Imports PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite
Imports SPWeb = Microsoft.SharePoint.SPWeb
Imports PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb
Imports PublishingWebCollection = Microsoft.SharePoint.Publishing.PublishingWebCollection
Imports SPWebTemplate = Microsoft.SharePoint.SPWebTemplate

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class PublishingWebCollectionCodeSamples


        Private Sub New()
        End Sub
        Public Shared Sub CreatePublishingWebBelowRoot(ByVal site As SPSite, ByVal webTemplate As SPWebTemplate)
' Replace these variable values and input parameters with 
' your own values.
Dim yourWebUrlName As String = "yourWebUrl" ' your web URL name for the PublishingWeb to create

Dim newWeb As PublishingWeb = Nothing

Try
    ' Validate the input parameters.
    If Nothing Is site Then
        Throw New System.ArgumentNullException("site")
    End If
    If Nothing Is webTemplate Then
        Throw New System.ArgumentNullException("webTemplate")
    End If

    Dim publishingSite As PublishingSite = Nothing
    If Not PublishingSite.IsPublishingSite(site) Then
        Throw New System.ArgumentException("The SPSite is expected to be a PublishingSite", "site")
    End If
    publishingSite = New PublishingSite(site)

    Dim rootWeb As SPWeb = publishingSite.RootWeb
    If Not PublishingWeb.IsPublishingWeb(rootWeb) Then
        Throw New System.ArgumentException("The SPSite.RootWeb is expected to be a PublishingWeb", "site")
    End If

    Dim rootPublishingWeb As PublishingWeb = PublishingWeb.GetPublishingWeb(rootWeb)
    Dim publishingWebs As PublishingWebCollection = rootPublishingWeb.GetPublishingWebs()

    ' Create the new PublishingWeb using the example values provided.
    newWeb = publishingWebs.Add(yourWebUrlName, rootWeb.Language, webTemplate.Name) ' Replace with your Web template name. -  Replace with your language value.

    ' The Publishing feature is active for the new PublishingWeb.
    System.Diagnostics.Debug.Assert(Nothing IsNot newWeb.Web.Features(Microsoft.SharePoint.Publishing.FeatureIds.Publishing))

Finally
    ' Always close the SPWeb when done to release memory.
    '
    If Nothing IsNot newWeb Then
        newWeb.Web.Close()
    End If
End Try

        End Sub
    End Class
End Namespace
Show: