Partager via


PublishingWeb.SetAvailablePageLayouts - Méthode

Spécifie les objets PageLayout sont disponibles pour une utilisation lors de la création d'objets PublishingPage dans cet objet PublishingWeb .

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

Syntaxe

'Déclaration
Public Sub SetAvailablePageLayouts ( _
    pageLayouts As PageLayout(), _
    resetAllSubsitesToInherit As Boolean _
)
'Utilisation
Dim instance As PublishingWeb
Dim pageLayouts As PageLayout()
Dim resetAllSubsitesToInherit As Boolean

instance.SetAvailablePageLayouts(pageLayouts, _
    resetAllSubsitesToInherit)
public void SetAvailablePageLayouts(
    PageLayout[] pageLayouts,
    bool resetAllSubsitesToInherit
)

Paramètres

  • resetAllSubsitesToInherit
    Type : System.Boolean

    Ce paramètre booléen indique si les objets disponibles PageLayout doivent être basculés vers le bas à tous les sous-sites.

Remarques

Après avoir appelé cette méthode, la méthode GetAvailablePageLayouts renvoie les objets de PageLayout de ce jeu. Les propriétéset IsAllowingAllPageLayouts() de **IsInheritingAvailablePageLayouts()**ont la valeur False.

Pour enregistrer les modifications apportées après l'appel de cette méthode, appelez la méthode Update .

Notes

Cette opération est synchrone.

Exemples

Cet exemple limite l'ensemble de mises en page disponibles utilisées pour créer des pages dans une publication Web afin que seules les mises en page associés à un type de contenu spécifié sont disponibles.

Avant d'utiliser cet exemple, vérifiez que le paramètre associatedContentTypeId est un type de contenu sur le site Web racine du site.

using SPContentTypeId = Microsoft.SharePoint.SPContentTypeId;
using SPContentType = Microsoft.SharePoint.SPContentType;
using SPSite = Microsoft.SharePoint.SPSite;
using SPFile = Microsoft.SharePoint.SPFile;
using SPWeb = Microsoft.SharePoint.SPWeb;
using PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite;
using PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb;
using PageLayoutCollection = Microsoft.SharePoint.Publishing.PageLayoutCollection;
using PageLayout = Microsoft.SharePoint.Publishing.PageLayout;

namespace Microsoft.SDK.SharePointServer.Samples
{
    public static class PublishingWebCodeSamples
    {
  
        public static void RestrictPageLayoutsByContentType(
PublishingWeb publishingWeb, 
SPContentTypeId associatedContentTypeId)
        {
// Replace these variable values and input parameters with your own values.
bool excludeHiddenLayouts = true;
bool resetAllSubsitesToInherit = true;

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

SPSite site = publishingWeb.Web.Site;
PublishingSite publishingSite = new PublishingSite(site);

// Retrieve a collection of all page layouts in the site collection
// that match the content type.
SPContentType associatedContentType = publishingSite.ContentTypes[associatedContentTypeId];
if (null == associatedContentType)
{
    throw new System.ArgumentException(
        "The SPContentTypeId did not match an SPContentType in the SPSite.RootWeb",
        "associatedContentTypeId");
}

PageLayoutCollection pageLayoutsByContentType = 
    publishingSite.GetPageLayouts(associatedContentType, excludeHiddenLayouts);

// Update the Web to use these page layouts when creating pages.
publishingWeb.SetAvailablePageLayouts(
    pageLayoutsByContentType.ToArray(),
    resetAllSubsitesToInherit);

publishingWeb.Update();

//  Verify the expected results. Note: This is not required. It demonstrates
//  the results of calling the SetAvailablePageLayouts method.
//
System.Diagnostics.Debug.Assert(!publishingWeb.IsAllowingAllPageLayouts);
System.Diagnostics.Debug.Assert(!publishingWeb.IsInheritingAvailablePageLayouts);

PageLayout[] availablePageLayouts = publishingWeb.GetAvailablePageLayouts();
foreach (PageLayout pageLayout in availablePageLayouts)
{
    System.Diagnostics.Debug.Assert(
        pageLayout.AssociatedContentType.Id == associatedContentTypeId);
}
        }
    }
}
Imports SPContentTypeId = Microsoft.SharePoint.SPContentTypeId
Imports SPContentType = Microsoft.SharePoint.SPContentType
Imports SPSite = Microsoft.SharePoint.SPSite
Imports SPFile = Microsoft.SharePoint.SPFile
Imports SPWeb = Microsoft.SharePoint.SPWeb
Imports PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite
Imports PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb
Imports PageLayoutCollection = Microsoft.SharePoint.Publishing.PageLayoutCollection
Imports PageLayout = Microsoft.SharePoint.Publishing.PageLayout

Namespace Microsoft.SDK.SharePointServer.Samples
    Public NotInheritable Class PublishingWebCodeSamples

        Private Sub New()
        End Sub
        Public Shared Sub RestrictPageLayoutsByContentType(ByVal publishingWeb As PublishingWeb, ByVal associatedContentTypeId As SPContentTypeId)
' Replace these variable values and input parameters with your own values.
Dim excludeHiddenLayouts As Boolean = True
Dim resetAllSubsitesToInherit As Boolean = True

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

Dim site As SPSite = publishingWeb.Web.Site
Dim publishingSite As New PublishingSite(site)

' Retrieve a collection of all page layouts in the site collection
' that match the content type.
Dim associatedContentType As SPContentType = publishingSite.ContentTypes(associatedContentTypeId)
If Nothing Is associatedContentType Then
    Throw New System.ArgumentException("The SPContentTypeId did not match an SPContentType in the SPSite.RootWeb", "associatedContentTypeId")
End If

Dim pageLayoutsByContentType As PageLayoutCollection = publishingSite.GetPageLayouts(associatedContentType, excludeHiddenLayouts)

' Update the Web to use these page layouts when creating pages.
publishingWeb.SetAvailablePageLayouts(pageLayoutsByContentType.ToArray(), resetAllSubsitesToInherit)

publishingWeb.Update()

'  Verify the expected results. Note: This is not required. It demonstrates
'  the results of calling the SetAvailablePageLayouts method.
'
System.Diagnostics.Debug.Assert((Not publishingWeb.IsAllowingAllPageLayouts))
System.Diagnostics.Debug.Assert((Not publishingWeb.IsInheritingAvailablePageLayouts))

Dim availablePageLayouts() As PageLayout = publishingWeb.GetAvailablePageLayouts()
For Each pageLayout As PageLayout In availablePageLayouts
    System.Diagnostics.Debug.Assert(pageLayout.AssociatedContentType.Id Is associatedContentTypeId)
Next pageLayout
        End Sub
    End Class
End Namespace

Voir aussi

Référence

PublishingWeb classe

PublishingWeb - Membres

Microsoft.SharePoint.Publishing - Espace de noms

GetAvailablePageLayouts

AllowAllPageLayouts

InheritAvailablePageLayouts