PublishingSite.GetPageLayouts - Méthode (SPContentType, Boolean)
Obtient une collection d'objets PageLayout à partir de la galerie de pages maîtres de la propriété RootWeb() qui possède une propriété AssociatedContentType qui correspond à un objet spécifique SPContentType .
Espace de noms : Microsoft.SharePoint.Publishing
Assembly : Microsoft.SharePoint.Publishing (dans Microsoft.SharePoint.Publishing.dll)
Syntaxe
'Déclaration
Public Function GetPageLayouts ( _
associatedContentType As SPContentType, _
excludeObsolete As Boolean _
) As PageLayoutCollection
'Utilisation
Dim instance As PublishingSite
Dim associatedContentType As SPContentType
Dim excludeObsolete As Boolean
Dim returnValue As PageLayoutCollection
returnValue = instance.GetPageLayouts(associatedContentType, _
excludeObsolete)
public PageLayoutCollection GetPageLayouts(
SPContentType associatedContentType,
bool excludeObsolete
)
Paramètres
associatedContentType
Type : Microsoft.SharePoint.SPContentTypeobjet SPContentType pour assurer la correspondance avec les valeurs de la propriété AssociatedContentType de le PageLayout les objets retournés dans la collection.
excludeObsolete
Type : System.BooleanIndicateur booléen qui indique s'il faut exclure les objets PageLayout qui sont marqués comme masquées.
Valeur renvoyée
Type : Microsoft.SharePoint.Publishing.PageLayoutCollection
Une collection d'objets PageLayout à partir de la galerie de pages maîtres de la propriété RootWeb qui ont une propriété AssociatedContentType qui correspond à un objet spécifique SPContentType .
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | Indique que le paramètre associatedContentType est une référence Null (Rien dans Visual Basic), qui n'est pas valide. |
Remarques
Le paramètre associatedContentType ne doit pas être une référence Null (Rien dans Visual Basic). Si le paramètre excludeObsolete est défini sur true, obsolète PageLayout les objets qui ont été marqués comme masquée sont pas retourné dans la collection. Si le paramètre excludeObsolete est défini sur false, les objets obsolètes PageLayout sont inclus dans la collection.
Exemples
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
{
// This sample restricts the set of available page layouts used
// for creating pages in a publishing Web so that only page layouts
// associated with a certain content type are available.
//
// Prerequisites:
// The associatedContentTypeId parameter is from a content
// type on the root Web site of the site.
//
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 (this is not required,
// and simply 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 SPSite = Microsoft.SharePoint.SPSite
Imports PublishingSite = Microsoft.SharePoint.Publishing.PublishingSite
Imports SPWeb = Microsoft.SharePoint.SPWeb
Imports PublishingWeb = Microsoft.SharePoint.Publishing.PublishingWeb
Imports PublishingWebCollection = Microsoft.SharePoint.Publishing.PublishingWebCollection
Imports SPWebTemplate = Microsoft.SharePoint.SPWebTemplate
Namespace Microsoft.SDK.SharePointServer.Samples
Public NotInheritable Class PublishingWebCollectionCodeSamples
' This method creates a new PublishingWeb below the root Web site of a PublishingSite object.
'
' Prerequisites:
' The SPSite passed should be a site that supports publishing.
'
' This sample demonstrates use of:
' PublishingSite.IsPublishingSite( SPSite )
' PublishingSite constructor
' PublishingSite.RootWeb
' PublishingWeb.GetPublishingWebs()
' PublishingWeb.Web
' PublishingWebCollection.Add(string, uint, string)
Private Sub New()
End Sub
Public Shared Sub CreatePublishingWebBelowRoot(ByVal site As SPSite, ByVal webTemplate As SPWebTemplate)
' Replace these variable values and input parameters with your own values.
' yourWebURL: name for the PublishingWeb object to create.
Dim yourWebUrlName As String = "yourWebUrl"
Dim newWeb As PublishingWeb = Nothing
Try
'
' Validate the input parameters.
'
If Nothing Is site Then
Throw New System.ArgumentNullException("site")
End If
If Nothing Is webTemplate Then
Throw New System.ArgumentNullException("webTemplate")
End If
Dim publishingSite As PublishingSite = Nothing
If Not PublishingSite.IsPublishingSite(site) Then
Throw New System.ArgumentException("The SPSite is expected to be a PublishingSite", "site")
End If
publishingSite = New PublishingSite(site)
Dim rootWeb As SPWeb = publishingSite.RootWeb
If Not PublishingWeb.IsPublishingWeb(rootWeb) Then
Throw New System.ArgumentException("The SPSite.RootWeb is expected to be a PublishingWeb", "site")
End If
Dim rootPublishingWeb As PublishingWeb = PublishingWeb.GetPublishingWeb(rootWeb)
Dim publishingWebs As PublishingWebCollection = rootPublishingWeb.GetPublishingWebs()
'
' Create the new PublishingWeb object by using the sample values provided.
'
newWeb = publishingWebs.Add(yourWebUrlName, rootWeb.Language, webTemplate.Name) ' Replace with your Web template name. - Replace with your own language value.
' The new PublishingWeb has the Publishing feature active.
System.Diagnostics.Debug.Assert(Nothing IsNot newWeb.Web.Features(Microsoft.SharePoint.Publishing.FeatureIds.Publishing))
Finally
'
' Always close the SPWeb object when done to release memory.
'
If Nothing IsNot newWeb Then
newWeb.Web.Close()
End If
End Try
End Sub
End Class
End Namespace