Compartilhar via


PublishingPageCollection.Add método (String, PageLayout)

Cria um novo PublishingPage no PublishingPageCollection do objeto PublishingWeb .

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

Sintaxe

'Declaração
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 retornado

Tipo: Microsoft.SharePoint.Publishing.PublishingPage
Recém-criado PublishingPage.

Exceções

Exceção Condição
[System.ArgumentException]

Valor inválido. O valor não pode ser uma sequência vazia.

[System.ArgumentException]

Extensão que não é válido para o nome da URL PublishingPage . PublishingPage Nomes de URL devem ter o de extensão de nome de arquivo . aspx.

[System.IO.PathTooLongException]

Nome de arquivo ou pasta especificado é muito longo. O caminho da URL para todos os arquivos e pastas deve ser 260 caracteres ou menos (e não mais de 128 caracteres para qualquer nome de arquivo ou pasta na URL). Digite um nome de arquivo ou pasta mais curto.

[Microsoft.SharePoint.SPException]

Já existe um arquivo com o nome de x . Ele foi modificado pela última vez y em z.

[Microsoft.SharePoint.SPException]

Nome de arquivo ou pasta x contém caracteres que não são permitidos. Use um nome diferente.

[System.ArgumentNullException]

Um dos parâmetros de entrada é uma referência nula (Nothing no Visual Basic).

[System.UnauthorizedAccessException]

Usuário atual não tem permissões suficientes para executar essa ação.

[System.IO.FileLoadException]

Outro arquivo com o mesmo nome já existe.

[System.IO.DirectoryNotFoundException]

Não há um problema com o parâmetro name .

Comentários

O valor de name não pode estar vazio e não pode exceder 128 caracteres. Se ele exceder o número máximo de caracteres, ele será aparado. O nome também deve ser exclusivo dentro do pai PublishingWeb.

O name não pode conter qualquer um dos seguintes caracteres inválidos: ", #, %), *,:, <>,, 2 _, \, /, {, |,}, &, ou caractere ASCII 0x7f.

O valor de layout deve ser um PageLayout do conjunto de sites atual. Geralmente, o PageLayout deve ser um membro do PageLayoutCollection que é retornado pelo método Publishing.GetAvailablePageLayouts , mas SharePoint 2010 não impor isso.

O novo PublishingPage tem os seguintes valores de propriedade.

Propriedade

Valor

PublishingPage.PublishingWeb

PublishingWeb que contém o PublishingPageCollection.

PublishingPage.ContentType

valor de AssociatedContentType para o layout.

PublishingPage.CreatedBy

Usuário de PublishingPage na data e hora em que este método foi chamado.

CreatedDate

Data e hora em que este método foi chamado.

PublishingPage.Description

Nenhum.

PublishingPage.EndDate

Nunca (null).

PublishingPage.LastModifiedBy

Usuário atual

PublishingPage.LastModifiedDate

Data e hora quando esse método foi chamado.

PublishingPage.Layout

valor do parâmetro layout .

PublishingPage.ListItem

SPListItem subjacente do PublishingPage.

PublishingPage.LocalContactEmail

Nenhuma.

PublishingPage.LocalContactImage

Nenhum.

PublishingPage.LocalContactName

None.

PublishingPage.Name

valor do parâmetro name .

PublishingPage.Contact

Usuário atual

PublishingPage.StartDate

Imediata (null).

PublishingPage.Title

Nenhuma.

PublishingPage.Url

URL relativa de servidor para o novo PublishingPage.

O usuário deve ter adicionar e editar permissões no PublishingWeb, especificamente para itens no PublishingWeb.PagesList, para usar esse método.

Exemplos

Este exemplo cria um novo objeto PublishingPage em um PublishingWeb.

Antes de compilação e a execução deste exemplo, verifique se um SPWeb que é um PublishingWeb existe e é passado como um parâmetro de Web.

PageLayout usados para criar a página deve ser passado no.

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

Ver também

Referência

PublishingPageCollection classe

PublishingPageCollection membros

Add em sobrecarga

Microsoft.SharePoint.Publishing namespace

[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)]