使用 SiteDefinition 将 ContentType 添加到列表

发布于 2024-09-12 04:27:39 字数 3316 浏览 3 评论 0原文

使用 SharePoint 2010 和 Visual Studio,我创建了一个网站定义(从发布网站继承),它正确创建了所有必需的列表,并且现在在“页面”文档库中包含页面实例。

页面使用正确的自定义页面布局和正确的内容类型,但是,因为“页面”库默认只接受文章、空白和欢迎页面,所以它不知道我的自定义内容类型,因此页面无法按预期工作。

我尝试在“添加列表”事件上添加事件监听器,但没有成功,调试甚至没有在断点处中断,我还尝试了添加列表、添加列表项和站点配置事件。这些似乎都没有按照我想要的方式工作。

我已在下面包含了站点定义的 XML,如何将自定义内容类型添加到页面库中,这样我就不必手动添加它?

<?xml version="1.0" encoding="utf-8"?>
<Project Title="Custom_Site_Definition" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
  <NavBars>
    <NavBar Name="SharePoint Top Navbar" Url="/Site Template" ID="1002" />
<!-- removed -->
  </NavBars>
  <Configurations>
    <Configuration ID="0" Name="Custom_Site_Definition">
      <Lists />
      <WebFeatures>
        <!-- Include the common WSSListTemplateFeatures used by CMS -->
        <Feature ID="00BFEA71-DE22-43B2-A848-C05709900100" > </Feature>
        <Feature ID="00BFEA71-E717-4E80-AA17-D0C71B360101" > </Feature>
        <Feature ID="00BFEA71-52D4-45B3-B544-B1C71B620109" > </Feature>
        <Feature ID="00BFEA71-A83E-497E-9BA0-7A5C597D0107" > </Feature>
        <Feature ID="00BFEA71-4EA5-48D4-A4AD-305CF7030140" > </Feature>
        <Feature ID="00BFEA71-F600-43F6-A895-40C0DE7B0117" > </Feature>

        <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5">
        </Feature>



        <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
          <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
            <Property Key="ChromeMasterUrl" Value=""/>
            <Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/at-a-glance.aspx"/>
            <Property Key="PagesListUrl" Value=""/>
            <Property Key="AvailableWebTemplates" Value=""/>
            <Property Key="AvailablePageLayouts" Value=""/>
            <Property Key="SimplePublishing" Value="true" />
          </Properties>
        </Feature>
        <Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA">
          <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
            <Property Key="InheritGlobalNavigation" Value="true"/>
            <Property Key="ShowSiblings" Value="true"/>
            <Property Key="IncludeSubSites" Value="true"/>
          </Properties>
        </Feature>
        <Feature ID="94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB">
          <!-- Office SharePoint Server Publishing -->
        </Feature>
      </WebFeatures>
      <Modules>
        <Module Name="Home" />
      </Modules>
    </Configuration>
  </Configurations>
  <Modules>
    <Module Name="Home" Url="$Resources:osrvcore,List_Pages_UrlName;" Path="">
      <File Url="at-a-glance.aspx" Type="GhostableInLibrary" Level="Draft" >
        <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/Custom Article Page.aspx, $Resources:cmscore,PageLayout_WelcomeLinks_Title;" />
      </File>
<!-- removed -->
    </Module>
  </Modules>
</Project> 

Using SharePoint 2010 and Visual Studio I have created a site definition (inheriting from the publishing site) which correctly creates all the required lists and now includes page instances in the "Pages" document library.

The Pages use the correct custom pagelayout and the correct content type, however, because the "pages" library only accepts Article, Blank and Welcome pages by default it doesnt know about my custom content types and therefore the page doesn't work as expected.

I've tried adding an EventListener on the "List Added" event, with no success, the debugging doesnt even break at my breakpoints, I've also tried the List Adding, List Item added and Site Provisioned events. None of which seem to work the way I want.

I've included the XML for the Site Definition below, how do I add my custom content types to the pages library so I dont have to manually add it?

<?xml version="1.0" encoding="utf-8"?>
<Project Title="Custom_Site_Definition" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
  <NavBars>
    <NavBar Name="SharePoint Top Navbar" Url="/Site Template" ID="1002" />
<!-- removed -->
  </NavBars>
  <Configurations>
    <Configuration ID="0" Name="Custom_Site_Definition">
      <Lists />
      <WebFeatures>
        <!-- Include the common WSSListTemplateFeatures used by CMS -->
        <Feature ID="00BFEA71-DE22-43B2-A848-C05709900100" > </Feature>
        <Feature ID="00BFEA71-E717-4E80-AA17-D0C71B360101" > </Feature>
        <Feature ID="00BFEA71-52D4-45B3-B544-B1C71B620109" > </Feature>
        <Feature ID="00BFEA71-A83E-497E-9BA0-7A5C597D0107" > </Feature>
        <Feature ID="00BFEA71-4EA5-48D4-A4AD-305CF7030140" > </Feature>
        <Feature ID="00BFEA71-F600-43F6-A895-40C0DE7B0117" > </Feature>

        <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5">
        </Feature>



        <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
          <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
            <Property Key="ChromeMasterUrl" Value=""/>
            <Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/at-a-glance.aspx"/>
            <Property Key="PagesListUrl" Value=""/>
            <Property Key="AvailableWebTemplates" Value=""/>
            <Property Key="AvailablePageLayouts" Value=""/>
            <Property Key="SimplePublishing" Value="true" />
          </Properties>
        </Feature>
        <Feature ID="541F5F57-C847-4e16-B59A-B31E90E6F9EA">
          <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
            <Property Key="InheritGlobalNavigation" Value="true"/>
            <Property Key="ShowSiblings" Value="true"/>
            <Property Key="IncludeSubSites" Value="true"/>
          </Properties>
        </Feature>
        <Feature ID="94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB">
          <!-- Office SharePoint Server Publishing -->
        </Feature>
      </WebFeatures>
      <Modules>
        <Module Name="Home" />
      </Modules>
    </Configuration>
  </Configurations>
  <Modules>
    <Module Name="Home" Url="$Resources:osrvcore,List_Pages_UrlName;" Path="">
      <File Url="at-a-glance.aspx" Type="GhostableInLibrary" Level="Draft" >
        <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/Custom Article Page.aspx, $Resources:cmscore,PageLayout_WelcomeLinks_Title;" />
      </File>
<!-- removed -->
    </Module>
  </Modules>
</Project> 

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

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

发布评论

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

评论(1

路弥 2024-09-19 04:27:39

没关系,我明白了...最终

解决方案是

  1. 向站点定义项目添加一个功能,并在其 elements.xml 文件中添加以下内容
<元素 xmlns="http://schemas.microsoft.com/sharepoint/">
  

然后在onet.xml文件中添加功能依赖项

<!-- Binds custom content types to Pages library.-->
<Feature ID="8290db1f-0a87-44f3-be22-28c61f9c8965">
</Feature>

,最后在文件末尾添加模块中的每个页面(包括内容类型)

 <File Url="at-a-glance.aspx" Type="GhostableInLibrary" Level="Draft" >
        <Property Name="Title" Value="At a glance" />
        <Property Name="ContentType" Value="Custom_ContentTypes_Publishing - CustomFive" />
        <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/Custom Article Page.aspx, $Resources:cmscore,PageLayout_WelcomeLinks_Title;" />
 </File>

Never mind, I got it...eventually

Solution was to

  1. Add a Feature to the site definition project with the following in its elements.xml file
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentTypeBinding ContentTypeId="0x010100899F73B9F6814EA9AED9876985F28B39" ListUrl="Pages" />
</Elements>

Then add a feature dependency in the onet.xml file

<!-- Binds custom content types to Pages library.-->
<Feature ID="8290db1f-0a87-44f3-be22-28c61f9c8965">
</Feature>

and finally to add each page in a module at the end of the file (including the content type)

 <File Url="at-a-glance.aspx" Type="GhostableInLibrary" Level="Draft" >
        <Property Name="Title" Value="At a glance" />
        <Property Name="ContentType" Value="Custom_ContentTypes_Publishing - CustomFive" />
        <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/Custom Article Page.aspx, $Resources:cmscore,PageLayout_WelcomeLinks_Title;" />
 </File>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文