PublishingPageCollection.Add - Méthode (String, PageLayout)

Crée un nouveau PublishingPage dans les PublishingPageCollection de l'objet PublishingWeb .

Espace de noms :  Microsoft.SharePoint.Publishing
Assembly :  Microsoft.SharePoint.Publishing (dans Microsoft.SharePoint.Publishing.dll)

Syntaxe

'Déclaration
Public Function Add ( _
    name As String, _
    layout As PageLayout _
) As PublishingPage
'Utilisation
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
)

Paramètres

Valeur renvoyée

Type : Microsoft.SharePoint.Publishing.PublishingPage
Le nouvellement créé PublishingPage.

Exceptions

Exception Condition
[System.ArgumentException]

Valeur non valide. La valeur ne peut pas être une chaîne vide.

[System.ArgumentException]

Extension n'est pas valide pour le nom de l'URL PublishingPage . PublishingPage Les noms d'URL doivent avoir l' extension du nom du fichier .aspx.

[System.IO.PathTooLongException]

Nom de fichier ou dossier spécifié est trop long. Le chemin d'URL pour tous les fichiers et dossiers doit être 260 caractères ou moins (et pas plus de 128 caractères pour n'importe quel fichier unique ou le nom du dossier dans l'URL). Tapez un nom de fichier ou de dossier plus court.

[Microsoft.SharePoint.SPException]

Fichier portant le nom x existe déjà. Dernière modification par y sur z.

[Microsoft.SharePoint.SPException]

Nom du fichier ou dossier x contient des caractères qui ne sont pas autorisés. Utilisez un nom différent.

[System.ArgumentNullException]

Un des paramètres d'entrée est une référence Null (Rien dans Visual Basic).

[System.UnauthorizedAccessException]

L'utilisateur actuel ne dispose pas des autorisations suffisantes pour effectuer cette action.

[System.IO.FileLoadException]

Un autre fichier portant le même nom existe déjà.

[System.IO.DirectoryNotFoundException]

Il existe un problème avec le paramètre name .

Remarques

La valeur de name ne peut pas être vide et ne peut pas dépasser 128 caractères. S'il dépasse le nombre maximal de caractères, il sera tronqué. Le nom doit également être unique dans le parent PublishingWeb.

Le name ne peut contenir aucun des caractères non valides suivants: ", #, %, *,:, <>,, ?, \, /, {, |,}, &, ou ASCII caractère 0x7f.

La valeur de layout doit être un PageLayout à partir de la collection de sites actuelle. En règle générale, la PageLayout doit être un membre de la PageLayoutCollection renvoyée par la méthode Publishing.GetAvailablePageLayouts , mais SharePoint 2010 n'applique pas cela.

La nouvelle PublishingPage a les valeurs de propriété suivantes.

Propriété

Valeur

PublishingPage.PublishingWeb

PublishingWeb qui contient la PublishingPageCollection.

PublishingPage.ContentType

valeur de AssociatedContentType pour la mise en page.

PublishingPage.CreatedBy

Utilisateur de PublishingPage à la date et l'heure, cette méthode a été appelée.

CreatedDate

Date et heure, que cette méthode a été appelée.

PublishingPage.Description

Aucun

PublishingPage.EndDate

Ne jamais (null).

PublishingPage.LastModifiedBy

Current user

PublishingPage.LastModifiedDate

Date et heure lorsque cette méthode a été appelée.

PublishingPage.Layout

valeur du paramètre layout .

PublishingPage.ListItem

SPListItem sous-jacent de la PublishingPage.

PublishingPage.LocalContactEmail

Aucune.

PublishingPage.LocalContactImage

Aucun

PublishingPage.LocalContactName

None.

PublishingPage.Name

valeur du paramètre name .

PublishingPage.Contact

Current user

PublishingPage.StartDate

Exécution (null).

PublishingPage.Title

Aucune.

PublishingPage.Url

URL relative de serveur pour le nouveau PublishingPage.

L'utilisateur doit disposer d'ajouter et modifier les autorisations dans le PublishingWeb, en particulier pour les éléments dans les PublishingWeb.PagesList, pour utiliser cette méthode.

Exemples

Cet exemple crée un nouvel objet PublishingPage dans une PublishingWeb.

Avant de compiler et exécuter cet exemple, vérifiez qu'un SPWeb qui est un PublishingWeb existe et qu'il est passé comme paramètre Web.

Les PageLayout utilisés pour la création de la page doit être transmis dans.

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

Voir aussi

Référence

PublishingPageCollection classe

PublishingPageCollection - Membres

Add - Surcharge

Microsoft.SharePoint.Publishing - Espace de noms

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