Compartir a través de


Clase PublishingWeb

Proporciona el comportamiento de publicación para una instancia de SPWeb compatible con la publicación.

Jerarquía de la herencia

System.Object
  Microsoft.SharePoint.Publishing.PublishingWeb

Espacio de nombres:  Microsoft.SharePoint.Publishing
Ensamblado:  Microsoft.SharePoint.Publishing (en Microsoft.SharePoint.Publishing.dll)

Sintaxis

'Declaración
Public NotInheritable Class PublishingWeb
'Uso
Dim instance As PublishingWeb
public sealed class PublishingWeb

Comentarios

La clase PublishingWeb proporciona un comportamiento específico de la publicación de un SPWeb que permite publicar, incluido el acceso a la PublishingPage del niño y las instancias de PublishingWeb , variaciones apoyo, configuración de exploración, PageLayout y restricciones de la plantilla de Web y configuración de la página de bienvenida. Esta clase ajusta una instancia de SPWeb que tiene activada la característica de publicación.

Crear una instancia de esta clase mediante el método estático GetPublishingWeb(SPWeb) o recuperarlos de una colección de PublishingWebCollection .

La clase PublishingWeb contiene la clase SPWeb . Expone también directamente la base SPWeb a través de la propiedad Web para que se puede acceder fácilmente la funcionalidad adicional de SPWeb .

Los miembros expuestos por esta clase están optimizados para el contexto actual de SPSite . Intenta utilizar métodos en la clase PublishingWeb para devolver los objetos de una colección de sitios diferentes pueden dar lugar a comportamientos inesperados, y hacerlo por lo que no es compatible.

Ejemplos

using System;
using System.IO;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;

namespace Microsoft.SDK.SharePoint.Samples.PublishingWebSample
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("Starting sample tests execution...");

            #region  PublishingWeb example

            //
            // ---------------------------------------------------------------------------------------
            // PublishingWeb example
            // ---------------------------------------------------------------------------------------
            // Passing the full url of a PublishingWeb.
            //
            // To compile add additional references to 
            // - System.Web.dll
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //

            //
            // You need to pass one parameter which is the full url of a PublishingWeb.
            //
            if (args.Length < 1)
            {
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("You need to pass the full url of a PublishingWeb.");
                FinishSampleTest();
                return;
            }

            string url = args[0];

            //
            // The url must be in the correct format.
            //
            Uri webUri = null;
            if (!Uri.TryCreate(url, UriKind.Absolute, out webUri))
            {
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("The url is not in correct format.");
                FinishSampleTest();
                return;
            }

            SPSite site = null;
            try
            {
                site = new SPSite(url);
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("The url is not a valid PublishingWeb.");
                FinishSampleTest();
                return;
            }

            using (SPWeb web = site.OpenWeb(HttpUtility.UrlDecode(webUri.AbsolutePath)))
            {
                PublishingWeb area = null;

                //
                // The url must be the full url of a PublishingWeb.
                //
                if (!web.Exists || !PublishingWeb.IsPublishingWeb(web))
                {
                    Console.WriteLine("--------------------------------------");
                    Console.WriteLine("The url is not a valid PublishingWeb.");
                    FinishSampleTest();
                    return;
                }

                area = PublishingWeb.GetPublishingWeb(web);
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Print out some properties of the current PublishingWeb:");
                PrintPublishingWebProperty(area);


                //
                // Create a PublishingPage examples: 
                //

                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Adding the 1st PublishingPage...");

                //
                // Create a new PublishingPage using default PageLayout.
                // 
                PublishingPage page1 = area.AddPublishingPage();
                Console.WriteLine("Sucessfully added the 1st PublishingPage.");

                // 
                // Check in the 1st PublishingPage.
                //
                if (page1.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None)
                {
                    Console.WriteLine("Check-in the 1st PublishingPage...");
                    page1.CheckIn("The PublishingPage page1 1st check in.");
                    Console.WriteLine("Successfully checked-in the 1st PublishingPage.");
                }

                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Try to add the 2nd PublishingPage using the default PageLayout of the PublishingWeb...");
                PageLayout defaultPageLayout = area.DefaultPageLayout;
                PublishingPage page2 = null;

                string page2Url = area.Web.Url + "/Pages/Page2.aspx";

                // 
                //  Get a PublishingPage by its url.
                // 
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("First try to see whether the PublisingPage with the same Url already exists:");
                page2 = area.GetPublishingPage(page2Url);
                Console.WriteLine("The Url of the PublishingPage is :" + page2Url);

                if (page2 != null)
                {
                    Console.WriteLine("The PublishingPage with Url {0} already exists.", page2Url);
                }
                else
                {
                    Console.WriteLine("The PublishingPage with Url {0} does not exist.", page2Url);
                    Console.WriteLine("Adding the 2nd PublishingPage...");
                    page2 = area.AddPublishingPage("Page2.aspx", defaultPageLayout);
                    Console.WriteLine("Sucessfully added the 2nd PublishingPage.");

                    // 
                    // Check in the 2nd PublishingPage.
                    //
                    if (page2.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None)
                    {
                        Console.WriteLine("Check-in the 2nd PublishingPage...");
                        page2.CheckIn("The PublishingPage page2 1st check in.");
                        Console.WriteLine("Successfully checked-in the 2nd PublishingPage.");
                    }
                }

                //
                // Get a PublishingPage examples: 
                //

                // 
                // Get a PublishingPage by its ID.
                // 
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Try to retrieve the PublisingPage by its ID:");
                int page1ID = page1.ListItem.ID;
                Console.WriteLine("The ID of the PublishingPage is :" + page1ID);
                PublishingPage page3 = area.GetPublishingPage(page1ID);

                // 
                //  Check out the PublishingPage, and edit its properties, then check it in.
                //
                if (page3 != null)
                {
                    Console.WriteLine("The PublishingPage with ID {0} is found.", page1ID);

                    if (page3.ListItem.File.CheckOutType == SPFile.SPCheckOutType.None)
                    {
                        Console.WriteLine("Check-out the PublishingPage...");
                        page3.CheckOut();
                        Console.WriteLine("Successfully checked-out the PublishingPage.");
                    }

                    Console.WriteLine("Updating the title of the PublishingPage to be 'Page3'...");
                    page3.Title = "Page3";
                    page3.Update();
                    Console.WriteLine("Successfully updated the PublishingPage.");

                    if (page3.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None)
                    {
                        Console.WriteLine("Check-in the PublishingPage...");
                        page3.CheckIn("Update the title to be Page3.");
                        Console.WriteLine("Successfully checked-in the PublishingPage.");
                    }
                }

                //
                // Iterate the whole PublishingPage List.
                //
                Console.WriteLine("--------------------------------------");
                Console.WriteLine("Iterate through the Pages library:");
                area.IterateOverAllPages(
                 delegate(PublishingPage page)
                 {
                     PrintPageUrl(page);
                 });
            }

            if (site != null)
            {
                site.Close();
            }

            #endregion

            Console.WriteLine("--------------------------------------");
            Console.WriteLine("Sample tests completed.");

            FinishSampleTest();
        }

        static void PrintPublishingWebProperty(PublishingWeb area)
        {
            PrintPublishingWebProperty(area, "ImagesLibrary", area.ImagesLibrary.Title);
            PrintPublishingWebProperty(area, "DocumentsLibrary", area.DocumentsLibrary.Title);
        }

        static void PrintPublishingWebProperty(PublishingWeb area, string propertyName, string propertyValue)
        {
            Console.WriteLine("The property {0} of PublishingWeb {1} is: {2}.", propertyName, area.Name, propertyValue);
        }

        static void PrintPageUrl(PublishingPage page)
        {
            Console.WriteLine("The Url of PublishingPage " + page.Name + " is " + page.Url + ".");
        }

        static void FinishSampleTest()
        {
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
    }
}
// Access the Pages list information without creating a PublishingWeb
// object.
using (SPSite site = new SPSite("http://myteam/team/"))
{
    using (SPWeb web = site.OpenWeb())
    {
        if (PublishingWeb.IsPublishingWeb(web))
        {
// Get the ID for the Pages list if we 
// know that Web is a PublishingWeb.
Guid pagesListId = PublishingWeb.GetPagesListId(web);

// Get the list by way of the ID.
SPList pagesList = web.Lists[pagesListId];

// Get the Pages list URL. Note:
// PublishingWeb.GetPagesListName(web)
// is equivalent to pagesList.RootFolder.Url.
string pagesListUrl = PublishingWeb.GetPagesListName(web);
        }
        else
        {
// If the SPWeb is not a PublishingWeb, 
// then GetPagesListName returns the URL
// that would be used by the Pages list 
// if the Publishing feature were to be
// activated.
string pagesListName = PublishingWeb.GetPagesListName(web);
        }
    }
}

// You can also create a PublishingWeb and access
// the properties from it.
using (SPSite site = new SPSite("http://myteam/"))
{
    using (SPWeb web = site.OpenWeb())
    {
        PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

        // Get the ID for the Pages list.
        Guid pagesListId = publishingWeb.PagesListId;

        SPList pagesList = publishingWeb.PagesList;

        // The PublishingWeb.PagesListName is equivalent 
        // to PublishingWeb.PagesList.RootFolder.Url.
        string pagesListUrl = publishingWeb.PagesListName;
    }
}
' Access the Pages list information without creating a PublishingWeb
' object.
Using site As New SPSite("http://myteam/team/")
    Using web As SPWeb = site.OpenWeb()
        If PublishingWeb.IsPublishingWeb(web) Then
' Get the ID for the Pages list if we 
' know that Web is a PublishingWeb.
Dim pagesListId As Guid = PublishingWeb.GetPagesListId(web)

' Get the list by way of the ID.
Dim pagesList As SPList = web.Lists(pagesListId)

' Get the Pages list URL. Note:
' PublishingWeb.GetPagesListName(web)
' is equivalent to pagesList.RootFolder.Url.
Dim pagesListUrl As String = PublishingWeb.GetPagesListName(web)
        Else
' If the SPWeb is not a PublishingWeb, 
' then GetPagesListName returns the URL
' that would be used by the Pages list 
' if the Publishing feature were to be
' activated.
Dim pagesListName As String = PublishingWeb.GetPagesListName(web)
        End If
    End Using
End Using

' You can also create a PublishingWeb and access
' the properties from it.
Using site As New SPSite("http://myteam/")
    Using web As SPWeb = site.OpenWeb()
        Dim publishingWeb As PublishingWeb = PublishingWeb.GetPublishingWeb(web)

        ' Get the ID for the Pages list.
        Dim pagesListId As Guid = publishingWeb.PagesListId

        Dim pagesList As SPList = publishingWeb.PagesList

        ' The PublishingWeb.PagesListName is equivalent 
        ' to PublishingWeb.PagesList.RootFolder.Url.
        Dim pagesListUrl As String = publishingWeb.PagesListName
    End Using
End Using

Seguridad para subprocesos

Los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para subprocesos. No se garantiza que los miembros de instancias sean seguros para los subprocesos.

Vea también

Referencia

Miembros PublishingWeb

Espacio de nombres Microsoft.SharePoint.Publishing

GetPublishingWeb

GetPublishingWebs