PublishingWeb.GetPublishingWebs Method (Microsoft.SharePoint.Publishing)
Returns child PublishingWeb objects immediately below this PublishingWeb object.

Namespace: Microsoft.SharePoint.Publishing
Assembly: Microsoft.SharePoint.Publishing (in microsoft.sharepoint.publishing.dll)
Syntax

Visual Basic (Declaration)
Public Function GetPublishingWebs As PublishingWebCollection
Visual Basic (Usage)
Dim instance As PublishingWeb
Dim returnValue As PublishingWebCollection

returnValue = instance.GetPublishingWebs
C#
public PublishingWebCollection GetPublishingWebs ()

Return Value

A PublishingWebCollection collection with all child PublishingWeb objects immediately below this PublishingWeb.
Remarks

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

Example

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

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

[c#]

using SPSite = Microsoft.SharePoint.SPSite;
using PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite;
using SPWeb = Microsoft.SharePoint.SPWeb;
using PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb;
using PublishingWebCollection = Microsoft.SharePoint.Publishing.PublishingWebCollection;
using SPWebTemplate = Microsoft.SharePoint.SPWebTemplate;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PublishingWebCollectionCodeSamples
    {

        
        public static void CreatePublishingWebBelowRoot( SPSite site, SPWebTemplate webTemplate )
        {
            // TODO: Replace these variable values and input parameters with 
            // your own values.
            string yourWebUrlName = "yourWebUrl";   // your web URL name for the PublishingWeb to create

            PublishingWeb newWeb = null;

            try
            {
                // Validate the input parameters.
                if (null == site)
                {
                    throw new System.ArgumentNullException("site");
                }
                if (null == webTemplate)
                {
                    throw new System.ArgumentNullException("webTemplate");
                }

                PublishingSite publishingSite = null;
                if (!PublishingSite.IsPublishingSite(site))
                {
                    throw new System.ArgumentException(
                        "The SPSite is expected to be a PublishingSite",
                        "site");
                }
                publishingSite = new PublishingSite( site );

                SPWeb rootWeb = publishingSite.RootWeb;
                if( !PublishingWeb.IsPublishingWeb( rootWeb ))
                {
                    throw new System.ArgumentException(
                        "The SPSite.RootWeb is expected to be a PublishingWeb",
                        "site");
                }

                PublishingWeb rootPublishingWeb = PublishingWeb.GetPublishingWeb( rootWeb );
                PublishingWebCollection publishingWebs = rootPublishingWeb.GetPublishingWebs();

                // Create the new PublishingWeb using the sample values provided.
                newWeb = publishingWebs.Add(
                    yourWebUrlName,
                    rootWeb.Language,   // TODO: Replace with your language value.
                    webTemplate.Name ); // TODO: Replace with your Web template name.

                // The Publishing feature is active for the new PublishingWeb.
                System.Diagnostics.Debug.Assert(
                    null != newWeb.Web.Features[Microsoft.SharePoint.Publishing.FeatureIds.Publishing]);
                               
            }
            finally
            {
                // Always close the SPWeb when done to release memory.
                //
                if( null != newWeb )
                {
                    newWeb.Web.Close();
                }
            }

        }
    }
}
See Also

Tags :


Community Content

Keith Dahlby
SPWeb Leak
Because of how they are constructed internally, the PublishingWebs returned by indexing into or enumerating over this collection will not properly Dispose of their SPWeb references when Close() is called. Instead, the caller should omit Close() and call Web.Dispose() instead. This does not apply to objects created by Add(), as in the example.

http://solutionizing.net/2009/01/08/the-semi-disposable-publishingweb/

Tags :

Page view tracker