(SPContentType, Boolean) del método PublishingSite.GetPageLayouts
Obtiene una colección de objetos PageLayout de la Galería de páginas maestras de la propiedad RootWeb() que tiene una propiedad AssociatedContentType que coincide con un objeto específico de SPContentType .
Espacio de nombres: Microsoft.SharePoint.Publishing
Ensamblado: Microsoft.SharePoint.Publishing (en Microsoft.SharePoint.Publishing.dll)
Sintaxis
'Declaración
Public Function GetPageLayouts ( _
associatedContentType As SPContentType, _
excludeObsolete As Boolean _
) As PageLayoutCollection
'Uso
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
)
Parámetros
associatedContentType
Tipo: Microsoft.SharePoint.SPContentTypeSPContentType objeto que coincidan con los valores de la propiedad AssociatedContentType de los objetos PageLayout que se devuelven en la colección.
excludeObsolete
Tipo: System.BooleanIndicador booleano que indica si se deben excluir los objetos PageLayout que están marcados como ocultos.
Valor devuelto
Tipo: Microsoft.SharePoint.Publishing.PageLayoutCollection
Una colección de objetos de PageLayout de la Galería de páginas maestras de la propiedad RootWeb que tengan una propiedad AssociatedContentType que coincide con un objeto específico de SPContentType .
Excepciones
Excepción | Condición |
---|---|
ArgumentNullException | Indica que el parámetro associatedContentType es una referencia null (Nothing en Visual Basic), que no es válido. |
Comentarios
El parámetro associatedContentType no debe ser una referencia null (Nothing en Visual Basic). Si el parámetro excludeObsolete se establece en true, obsoleto PageLayout objetos que se han marcado como ocultos no se devuelve en la colección. Si el parámetro excludeObsolete se establece en false, objetos obsoletos PageLayout se incluyen en la colección.
Ejemplos
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