Compartir a través de


(String, PageLayout) del método PublishingPageCollection.Add

Crea un nuevo PublishingPage en la PublishingPageCollection del objeto PublishingWeb .

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

Sintaxis

'Declaración
Public Function Add ( _
    name As String, _
    layout As PageLayout _
) As PublishingPage
'Uso
Dim instance As PublishingPageCollection
Dim name As String
Dim layout As PageLayout
Dim returnValue As PublishingPage

returnValue = instance.Add(name, layout)
public PublishingPage Add(
    string name,
    PageLayout layout
)

Parámetros

Valor devuelto

Tipo: Microsoft.SharePoint.Publishing.PublishingPage
El recién creado PublishingPage.

Excepciones

Excepción Condición
[System.ArgumentException]

Valor no válido. El valor no puede ser una cadena vacía.

[System.ArgumentException]

Extensión que no es válido para el nombre de la dirección URL de PublishingPage . PublishingPage Nombres de dirección URL deben tener la extensión de nombre de archivo .aspx.

[System.IO.PathTooLongException]

Nombre de archivo o carpeta especificado es demasiado largo. La dirección URL para todos los archivos y carpetas debe tener 260 caracteres o menos (y no más de 128 caracteres para cualquier archivo único o el nombre de la carpeta en la dirección URL). Escriba un nombre de archivo o carpeta más corto.

[Microsoft.SharePoint.SPException]

Ya existe un archivo con el nombre x . Se modificó por última y en z.

[Microsoft.SharePoint.SPException]

Nombre del archivo o la carpeta x contiene caracteres que no están permitidos. Use un nombre diferente.

[System.ArgumentNullException]

Uno de los parámetros de entrada es una referencia null (Nothing en Visual Basic).

[System.UnauthorizedAccessException]

Usuario actual no tiene permisos suficientes para realizar esta acción.

[System.IO.FileLoadException]

Ya existe otro archivo con el mismo nombre.

[System.IO.DirectoryNotFoundException]

Hay un problema con el parámetro name .

Comentarios

El valor de name no puede estar vacío y no puede exceder de 128 caracteres. Si se excede el número máximo de caracteres, se recortará. El nombre también debe ser único en el elemento primario PublishingWeb.

El name no puede contener ninguno de los siguientes caracteres no válidos: ", #, %, *,:, <>,, ?, \, /, {, |,} &, o ASCII carácter 0x7f.

El valor de layout debe ser un PageLayout de la colección de sitios actual. Por lo general, el PageLayout debe ser un miembro de la PageLayoutCollection devuelta por el método Publishing.GetAvailablePageLayouts , pero SharePoint 2010 no cumple esto.

El nuevo PublishingPage tiene los siguientes valores de propiedad.

Propiedad

Value

PublishingPage.PublishingWeb

PublishingWeb que contiene el PublishingPageCollection.

PublishingPage.ContentType

valor de AssociatedContentType para el diseño.

PublishingPage.CreatedBy

Usuario de PublishingPage en la fecha y hora que se llama a este método.

CreatedDate

Fecha y hora en que se llama a este método.

PublishingPage.Description

Ninguna.

PublishingPage.EndDate

Nunca (null).

PublishingPage.LastModifiedBy

Current User

PublishingPage.LastModifiedDate

Fecha y hora cuando se llama a este método.

PublishingPage.Layout

valor del parámetro layout .

PublishingPage.ListItem

Subyacente SPListItem de la PublishingPage.

PublishingPage.LocalContactEmail

Ninguna.

PublishingPage.LocalContactImage

Ninguna.

PublishingPage.LocalContactName

None.

PublishingPage.Name

valor del parámetro name .

PublishingPage.Contact

Current User

PublishingPage.StartDate

Inmediato (null).

PublishingPage.Title

Ninguna.

PublishingPage.Url

URL relativa al servidor para el nuevo PublishingPage.

El usuario debe tener agregar y editar los permisos en el PublishingWeb, específicamente para los elementos de la PublishingWeb.PagesList, para utilizar este método.

Ejemplos

En este ejemplo se crea un nuevo objeto PublishingPage en un PublishingWeb.

Antes de compilar y ejecutar este ejemplo, compruebe que existe un SPWeb que es un PublishingWeb y que se pasa como un parámetro de Web.

El PageLayout que se usa para crear la página debe pasarse en.

using SPWeb = Microsoft.SharePoint.SPWeb;
using PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb;
using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;
using PublishingPageCollection = Microsoft.SharePoint.Publishing.PublishingPageCollection;
using PublishingPage = Microsoft.SharePoint.Publishing.PublishingPage;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PublishingPageCollectionCodeSamples
    {
        public static void CreateNewPage( SPWeb web, PageLayout pageLayout )
        {
            // TODO: Replace these variable values with your own
            // values.
            //
            // The URL name of the new page
            string newPageName = "Contoso.aspx";
            //
            // The comment to set when the page is checked in.
            string checkInComment = "Your check in comments";

            // Validate the input parameters.
            if (null == web)
            {
                throw new System.ArgumentNullException("web");
            }
            if (null == pageLayout)
            {
                throw new System.ArgumentNullException("pageLayout");
            }

            // Get the PublishingWeb wrapper for the SPWeb
            // that was passed in.
            PublishingWeb publishingWeb = null;
            if (PublishingWeb.IsPublishingWeb(web))
            {
                publishingWeb = PublishingWeb.GetPublishingWeb(web);
            }
            else
            {
                throw new System.ArgumentException("The SPWeb must be a PublishingWeb", "web");
            }
           
            // Create the new page in the PublishingWeb.
            PublishingPageCollection pages = publishingWeb.GetPublishingPages();
            PublishingPage newPage = pages.Add(newPageName, pageLayout);

            // Check the new page in so that other contributors
            // can work on it.
            newPage.CheckIn(checkInComment);          
        }
    }
}
Imports SPWeb = Microsoft.SharePoint.SPWeb
Imports PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb
Imports PageLayout = Microsoft.SharePoint.Publishing.PageLayout
Imports PublishingPageCollection = Microsoft.SharePoint.Publishing.PublishingPageCollection
Imports PublishingPage = Microsoft.SharePoint.Publishing.PublishingPage

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class PublishingPageCollectionCodeSamples
        Private Sub New()
        End Sub
        Public Shared Sub CreateNewPage(ByVal web As SPWeb, ByVal pageLayout As PageLayout)
            ' TODO: Replace these variable values with your own
            ' values.
            '
            ' The URL name of the new page
            Dim newPageName As String = "Contoso.aspx"
            '
            ' The comment to set when the page is checked in.
            Dim checkInComment As String = "Your check in comments"

            ' Validate the input parameters.
            If Nothing Is web Then
                Throw New System.ArgumentNullException("web")
            End If
            If Nothing Is pageLayout Then
                Throw New System.ArgumentNullException("pageLayout")
            End If

            ' Get the PublishingWeb wrapper for the SPWeb
            ' that was passed in.
            Dim publishingWeb As PublishingWeb = Nothing
            If PublishingWeb.IsPublishingWeb(web) Then
                publishingWeb = PublishingWeb.GetPublishingWeb(web)
            Else
                Throw New System.ArgumentException("The SPWeb must be a PublishingWeb", "web")
            End If

            ' Create the new page in the PublishingWeb.
            Dim pages As PublishingPageCollection = publishingWeb.GetPublishingPages()
            Dim newPage As PublishingPage = pages.Add(newPageName, pageLayout)

            ' Check the new page in so that other contributors
            ' can work on it.
            newPage.CheckIn(checkInComment)
        End Sub
    End Class
End Namespace

Vea también

Referencia

clase PublishingPageCollection

Miembros PublishingPageCollection

Sobrecarga Add

Espacio de nombres Microsoft.SharePoint.Publishing

[Microsoft.SharePoint.Publishing.PublishingWeb.GetAvailablePageLayouts]

[Microsoft.SharePoint.Publishing.PublishingWeb.GetAvailablePageLayouts(Microsoft.SharePoint.SPContentTypeId)]

[Microsoft.SharePoint.Publishing.PublishingSite.GetPageLayouts(System.Boolean)]

[Microsoft.SharePoint.Publishing.PublishingSite.GetPageLayouts(Microsoft.SharePoint.SPContentType,System.Boolean)]

[Microsoft.SharePoint.Publishing.PublishingSite.GetPageLayouts(Microsoft.SharePoint.SPContentTypeId,System.Boolean)]

[Microsoft.SharePoint.Publishing.PublishingSite.GetPageLayouts(System.String,System.Boolean)]

[Microsoft.SharePoint.Publishing.PublishingSite.GetPageLayouts(System.String)]