2010-11-16 73 views
1

我正在开发一个拥有许多子站点的SharePoint 2010发布网站。我设置了一个自定义母版页和几个自定义页面布局。Sharepoint:如何更改新创建子网站的默认页面布局?

我发现了如何设置用于在子网站(在/_Layouts/AreaTemplateSettings.aspx找到)新创建的页面的默认页面布局,但我似乎无法弄清楚如何指定默认页面布局用于在创建新的子网站时创建〜/ Pages/default.aspx。

现在它选择WelcomeLinks.aspx,这不是我想要的。

这是唯一可用的,如果我通过代码部署自定义母版页/布局,如果是这样,有没有人有任何好的例子?

谢谢。

回答

3

您不需要部署自定义页面布局,但需要使用代码。我们解决这个问题的方法是为WebProvisioned事件创建一个事件接收器,该事件将在新的SPWeb创建后触发。

您可以做的是使用所需的页面布局更新新网站中的PublishingPage。这允许用户创建新的网站,但您可以设置每个新网站的默认页面布局。

这是事件接收器代码:

public override void WebProvisioned(SPWebEventProperties properties) 
{ 
    try 
    { 
     if (PublishingWeb.IsPublishingWeb(properties.Web)) 
     { 
      PublishingWeb curPubWeb = PublishingWeb.GetPublishingWeb(properties.Web); 

      foreach (PageLayout curLayout in curPubWeb.GetAvailablePageLayouts()) 
      { 
       if (curLayout.Name == "DefaultPageLayout.aspx") 
       { 
        foreach (PublishingPage curPage in curPubWeb.GetPublishingPages()) 
        { 
         curPage.CheckOut(); 
         curPage.Layout = curLayout; 
         curPage.Update(); 
         curPage.CheckIn(""); 
        } 
        break; 
       } 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     /* Handle exception here */ 
    } 
} 

这是注册事件接收器(可以当你的功能被激活,也可以从一个PowerShell脚本或控制台应用程序运行一次运行的代码):

using (SPSite topSite = new SPSite("[Site Collection URL]")) 
{ 
    SPEventReceiverDefinition webEventDef = topSite.EventReceivers.Add(); 
    webEventDef.Name = "Web Adding Receiver"; 
    webEventDef.Synchronization = SPEventReceiverSynchronization.Synchronous; 
    webEventDef.Type = SPEventReceiverType.WebProvisioned; 
    webEventDef.SequenceNumber = 4001; 
    webEventDef.Assembly = "MyCustomAssembly, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=123456789"; 
    webEventDef.Class = "MyCustomAssembly.CustomEvents"; 
    webEventDef.Data = "Adding publishingwebfeatures"; 
    webEventDef.Update(); 
} 
+0

美丽,谢谢。 – ScottE 2010-11-16 17:21:31

4

新创建的子网站的页面布局由网站定义确定。例如,如果使用带有工作流程模板的发布网站创建子网站,则使用14 \ TEMPLATE \ SiteTemplates \ BLANKINTERNET \ XML \ onet.xml中的配置ID =“2”创建该网站。在这一配置是一个模块部分指向SubWebWelcome:

<Module Name="SubWebWelcome" Url="$Resources:osrvcore,List_Pages_UrlName;" Path=""> 
    <File Url="default.aspx" Type="GhostableInLibrary" Level="Draft" > 
     <Property Name="Title" Value="$Resources:cmscore,IPPT_HomeWelcomePage_Title;" /> 
     <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/WelcomeLinks.aspx, $Resources:cmscore,PageLayout_WelcomeLinks_Title;" /> 
     <Property Name="ContentType" Value="$Resources:cmscore,contenttype_welcomepage_name;" /> 
    </File> 
</Module> 

正如你所看到的,SubWebWelcome规定使用WelcomeLinks页面布局的Default.aspx。

如果你想为默认页面不同的页面布局,你有两个选择:

  1. 创建基于使用你想要的页面布局BLANKINTERNET自定义网站定义。
  2. 继续使用自定义代码(由功能装订或事件接收器启动)将盒页面定义从WelcomeLinks更改为页面版式。
1

如果发布功能的站点启用,它应该是为打算简单:

站点设置,外观和感觉,欢迎页面并选择页面

0

看来,当您将发布子网站添加到SharePoint似乎不会继承父网站的默认页面布局。更重要的是,即使您拨打SetDefaultPageLayout传真以重置所有子网站,此设置仍然不会停留。

脚手架后我的整个网站结构(子网),我不得不实施以下递归函数,以确保最顶级的默认页面布局被继承,希望这可以帮助某人。

// Recursively update sub-webs to inherit the default page layout. 
Action<PublishingWeb> updateWebRecursive = null; 
updateWebRecursive = new Action<PublishingWeb>((parentWeb) => 
{ 
    PublishingWebCollection childWebs = parentWeb.GetPublishingWebs(); 
    if (!parentWeb.Web.IsRootWeb) 
    { 
     parentWeb.InheritDefaultPageLayout(); 
     parentWeb.Update(); 
    } 
    foreach (PublishingWeb childWeb in childWebs) 
    { 
     updateWebRecursive(childWeb); 
    } 
}); 
updateWebRecursive(pubWeb); 
相关问题