Метод PublishingSite.GetPageLayouts (SPContentType, Boolean)
Получает коллекцию объектов PageLayout из коллекции главных страниц, имеет свойство AssociatedContentType , которое соответствует объекту определенного SPContentType свойства RootWeb() .
Пространство имен: Microsoft.SharePoint.Publishing
Сборка: Microsoft.SharePoint.Publishing (в Microsoft.SharePoint.Publishing.dll)
Синтаксис
'Декларация
Public Function GetPageLayouts ( _
associatedContentType As SPContentType, _
excludeObsolete As Boolean _
) As PageLayoutCollection
'Применение
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
)
Параметры
associatedContentType
Тип: Microsoft.SharePoint.SPContentTypeОбъект SPContentType , в соответствии со значениями свойства AssociatedContentTypePageLayout объектов, возвращенных в коллекции.
excludeObsolete
Тип: System.BooleanЛогический флаг, который указывает, следует ли исключить PageLayout объектов, помеченных как скрытые.
Возвращаемое значение
Тип: Microsoft.SharePoint.Publishing.PageLayoutCollection
Коллекция объектов PageLayout из RootWeb свойства коллекции главных страниц, имеющих это свойство AssociatedContentType , которое соответствует объекту конкретного SPContentType .
Исключения
Исключение | Условие |
---|---|
ArgumentNullException | Указывает, что параметр associatedContentType является пустая ссылка (Nothing в Visual Basic), который не является допустимым. |
Замечания
Параметр associatedContentType не должно быть пустая ссылка (Nothing в Visual Basic). Если параметр excludeObsolete имеет значение true, устаревшие PageLayout объекты, которые не были помечены как скрытые являются возвращаемой коллекции. Если параметр excludeObsolete имеет значение false, устаревшие PageLayout объекты включаются в коллекции.
Примеры
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