Sharepoint:如何更改新创建的子网站的默认页面布局?

发布于 2024-10-02 10:56:10 字数 305 浏览 0 评论 0原文

我正在开发一个包含许多子网站的 sharepoint 2010 发布网站。我已经设置了一个自定义母版页和几个自定义页面布局。

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

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

仅当我通过代码部署自定义母版页/布局时,这才可用,如果是,有人有任何好的示例吗?

谢谢。

I'm working on a sharepoint 2010 publishing site that has many subsites. I've set up a custom master page, and several custom page layouts.

I've discovered how to set the default page layout used for newly created pages in a subsite (found at /_Layouts/AreaTemplateSettings.aspx), but I can't seem to figure out how to specify the default page layout used to create ~/Pages/default.aspx when I create a new subsite.

Right now it selects WelcomeLinks.aspx, and that's not what I want.

Is this only available if I deploy custom master pages / layouts via code, and if so, does anyone have any good examples?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

合约呢 2024-10-09 10:56:10

新创建的子网站的页面布局由网站定义决定。例如,如果您使用“使用工作流发布网站”模板创建子网站,则该网站将使用 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 的页面布局。

The Page Layout of a newly created subsite is determined by the site definition. For example, if you create a subsite using the Publishing Site with Workflow template, then that site is created using Configuration ID="2" from 14\TEMPLATE\SiteTemplates\BLANKINTERNET\XML\onet.xml. Within that configuration is a module section that points to 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>

As you can see, SubWebWelcome provisions the default.aspx using the WelcomeLinks Page Layout.

If you want a different Page Layout for the default page, you have two options:

  1. Create a custom site definition based on BLANKINTERNET that uses your desired Page Layout.
  2. Continue to use the out of the box site definition with custom code (launched by either feature stapling or event receivers) that changes the Page Layout from WelcomeLinks.
記柔刀 2024-10-09 10:56:10

您不需要部署自定义页面布局,但确实需要使用代码。我们解决此问题的方法是为 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();
}

You don't need to deploy a custom page layout but you do need to use code. The way we have solved this is to create an Event Receiver for the WebProvisioned event which will fire after a new SPWeb has been created.

What you can do is to update the PublishingPage in the new web with the Page Layout that you want. This allows users to create new webs but you to set the default Page Layout of each new web.

This is the event receiver code:

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 */
    }
}

And this is the code to register the event receiver (this can be run when your feature is activated or can be run once from a PowerShell script or console application):

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();
}
空心空情空意 2024-10-09 10:56:10

如果在站点上启用了发布功能,则应该非常简单:

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

If the Publishing feature is enabled at the site, it should be as simple as going to:

Site Settings, Look and Feel, Welcome Page and selecting the page

感受沵的脚步 2024-10-09 10:56:10

似乎当您将发布子网站添加到 SharePoint 时,它似乎没有继承父网站的默认页面布局。更重要的是,即使您调用 SetDefaultPageLayout 并传递 true 来重置所有子站点,此设置仍然不会保留。

在搭建了整个网站结构(子网站)之后,我必须实现以下递归函数以确保继承最顶层的默认页面布局,希望这对某人有帮助。

// 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);

It seems that when you add publishing sub webs to SharePoint it doesn't seem to inherit the parent webs default page layout. What is more is even if you call SetDefaultPageLayout passing true to reset all sub-sites, this setting still does not stick.

After scaffolding my entire site structure (sub-webs), I had to implement the following recursive function to ensure the top most default page layout is being inherited, hopefully this helps someone.

// 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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文