-2
如何设置用于以编程方式在SharePoint 2010中发布页面的默认页面布局?Programmaticaly为在SharePoint 2010中发布页面设置默认页面布局
如何设置用于以编程方式在SharePoint 2010中发布页面的默认页面布局?Programmaticaly为在SharePoint 2010中发布页面设置默认页面布局
类似于以下内容,其中layoutName
是文件名,例如MyDefaultLayout.aspx
。
void SetDefaultPageLayout(string layoutName, SPWeb web)
{
var pubWeb = PublishingWeb.GetPublishingWeb(web);
if (pubWeb != null)
{
var pageLayout = pubWeb.GetAvailablePageLayouts()
.Single(pl => pl.Name == layoutName);
pubWeb.SetDefaultPageLayout(pageLayout, true);
pubWeb.Update();
}
}