【问题标题】:Sharepoint 2010 - Hide "Title" field in Custom Content TypeSharepoint 2010 - 在自定义内容类型中隐藏“标题”字段
【发布时间】:2013-01-29 23:27:44
【问题描述】:

现在我在Custom Content Type 中定义一个新的Custom List Definition,问题只是与列表关联的Title 字段无法隐藏,我遵循了以下链接中的一些方法,但使用没有成功。

仅添加List definition 而不实现内容类型会使标题字段消失,但在定义内容类型及其字段时,它始终可见。

Elements.xml

  <ContentType ID="0x01003EBF692DD17B4F71966712180C0D23D8" Name="ContactUsAssignments"  
               Description="Contact Us Assignments content type">
    <FieldRefs>
      <FieldRef ID="{4B888F48-A039-46D0-B2E1-C67802097069}"/>
      <FieldRef ID="{6238a52d-2975-4e8a-9a1e-31b9cdc74129}"/>
      <RemoveFieldRef ID="{D3D0DDF1-F791-4FFF-893C-0C100B724F1A}" />
    </FieldRefs>
  </ContentType>

我也尝试过Inherits="FALSE" Version="0",但遗憾的是没有任何改变。

Schema.xml

  <ContentTypes>
    <ContentTypeRef ID="0x01003EBF692DD17B4F71966712180C0D23D8"></ContentTypeRef>
</ContentTypes>
<Fields>
  <Field Type="Text" DisplayName="Title" Required="FALSE"
   ID="{D3D0DDF1-F791-4FFF-893C-0C100B724F1A}" StaticName="Title" Name="Title" Hidden="TRUE" />
</Fields>

我不知道我是否错过了什么,但方法很清楚。谢谢。

【问题讨论】:

    标签: xml sharepoint sharepoint-2010 custom-lists


    【解决方案1】:

    这里提到的所有答案都经过测试,但没有成功。经过多次调查和属性组合,我想出了以下答案作为工作答案。

    一个。在每个list Definition 上的Elements.xml 文件上确保

    Inherits="FALSE"

    Content Type

    Hidden="TRUE" 必需="FALSE" DisplayName="_hidden"

    对于“Title”字段 定义。

    <ContentType ID="0x01007F465964D8114436BD7D7CF2C2D8CF01" Name="Categories" Group="Category CT" Description="Category content type" Inherits="FALSE">
        <FieldRefs>
          <FieldRef ID="{BA7EBEF9-338B-45DE-9743-E394873060A7}"/>
          <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Hidden="TRUE" Required="FALSE" DisplayName="_hidden" />
        </FieldRefs>
      </ContentType>
    

    b.删除schema.xmlTitle 字段的任何引用

    【讨论】:

    • 设置 Inherits="FALSE" 有何影响?
    • 最好的答案,花了几天才找到这个解决方案
    【解决方案2】:

    这是适用于我们所有项目的方法:

    在定义了所有自定义内容类型的 element.xml 中,添加下一行以隐藏“标题”字段。确保具有相同的 GUID,因为它是 OOTB SharePoint 标题字段:

    <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Title" Required="FALSE" Hidden="TRUE" />
    

    属性Required="FALSE" 和Hidden="TRUE" 很重要。这些行将在内容类型中起作用。

    另一个修改是内容类型定义。它应该看起来像:

    <ContentType ID="0x01005E47745D75A5422A9688FDCC0E6E855A"
                   Name="Links"
                   Group="YourGroup"
                   Description="YouDescription
                   Inherits="FALSE"
                   Version="0">
    

    Inherits="FALSE" 也很重要,因为内容类型应该停止继承默认项目属性,以便隐藏字段并使其成为可选。

    希望对你有帮助,

    安德鲁

    【讨论】:

      【解决方案3】:

      您是否尝试在 ContentType 定义上方的 Elements.xml 文件中添加标题字段定义?我在下面找到了两个将字段定义添加到 elements.xml 文件的示例。您可以尝试这样做并将Required设置为False并将Hidden设置为True,看看是否有效。

      http://msdn.microsoft.com/en-us/library/gg295290%28v=office.14%29.aspx

      http://www.codeproject.com/Articles/410880/SharePoint-2010-Creating-a-Custom-Content-Type-usi

      我从来没有完全这样做过,但是我有时会作弊并从列表定义中完全删除内容类型(保留为 )并像在 Schema.xml 中一样声明字段。以这种方式执行此操作会覆盖我的默认标题字段。

      【讨论】:

      • 我也试过这个。关于删除内容类型,这不会使列表能够通过 LINQ to Sharepoint 访问,对吗?
      【解决方案4】:

      尝试使用 Inherits="False" 指定删除 Title 字段。例如

      <?xml version="1.0" encoding="utf-8"?>
      <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <!-- Parent ContentType: Item (0x01) 
             Tracked user activity. -->
        <ContentType ID="0x0100c592d12a1dfa42ae8614d54f45118f83"
                     Name="User Activity"
                     Group="User Activity Tracking"
                     Description="Tracked user activity."
                     Inherits="FALSE"
                     Version="0">
          <FieldRefs>
            <!--Title field inherited from parent Item content type is not required.-->
            <RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />
            <FieldRef ID="{B2FCBA31-5888-4CB9-BCC8-7B1943161B40}" Name="UserActivityCreatedBy"/>
            <FieldRef ID="{B3F666F7-2DA3-402C-A1A2-A6AA9F4E3E86}" Name="UserActivityType"/>
            <FieldRef ID="{ABF63CC0-6201-44E7-BA8E-4C0116E5B09F}" Name="UserActivityTimeStamp"/>
          </FieldRefs>
        </ContentType>
      </Elements>
      

      在列表定义中添加 ref 到内容类型

          <ContentTypes>
            <ContentTypeRef ID="0x0100c592d12a1dfa42ae8614d54f45118f83"/>
          </ContentTypes>
      

      并且在字段部分不要描述标题字段

      <Fields>
            <Field ID="{b2fcba31-5888-4cb9-bcc8-7b1943161b40}" Name="UserActivityCreatedBy" Type="User" List="UserInfo" ShowField="Title" UserSelectionMode="0" UserSelectionScope="0" ReadOnlyEnforced="TRUE" Required="TRUE" DisplayName="Created By" StaticName="UserActivityCreatedBy" Group="User Activity Tracking"/>
            <Field ID="{b3f666f7-2da3-402c-a1a2-a6aa9f4e3e86}" Name="UserActivityType" Type="Choice" Format="Dropdown" FillInChoice="FALSE" DisplayName="Type" StaticName="UserActivityType" Group="User Activity Tracking">
              <Default>HttpRequest</Default>
              <CHOICES>
                <CHOICE>Login</CHOICE>
                <CHOICE>HttpRequest</CHOICE>
                <CHOICE>TermsOfUsageAcceptance</CHOICE>
              </CHOICES>
            </Field>
            <Field ID="{abf63cc0-6201-44e7-ba8e-4c0116e5b09f}" Name="UserActivityTimeStamp" Type="DateTime" Format="DateTime" StorageTZ="UTC" DisplayName="Time Stamp" StaticName="UserActivityTimeStamp" Group="User Activity Tracking"/>
          </Fields>
      

      别忘了描述适当的视图 - ViewFields 部分

              <ViewFields>
                <FieldRef Name="UserActivityCreatedBy" />
                <FieldRef Name="UserActivityType" />
                <FieldRef Name="UserActivityTimeStamp" />
              </ViewFields>
      

      【讨论】:

        【解决方案5】:

        这是一个适合我的解决方案:

        这是我的内容类型

        <ContentType ID="0x0100a2045db65601406a95f8f050642655b7"
                       Name="MyContentType"
                       Group="Custom Content Types"
                       Description="Content Type Description"
                       Inherits="FALSE"
                       Version="0">
        <FieldRefs>
             <!--removing the reference from the Title field-->
              <RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />
        
          ....
        
        </FieldRefs>
        

        这是我的 Schema.xml 部分,其中包含我的内容类型的引用。您必须从 schema.xml 视图中删除 titlefield。

            <ContentTypes>
                <ContentTypeRef ID="0x0100a2045db65601406a95f8f050642655b7"/>
            </ContentTypes>
        
        .....
        
            <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="MyView" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
                    <Toolbar Type="Standard" />
                    <XslLink Default="TRUE">main.xsl</XslLink>
                    <RowLimit Paged="TRUE">30</RowLimit>
                    <ViewFields>
                      <FieldRef Name="ID"></FieldRef>
        
                      <!--Delete the reference below -->
                      <FieldRef Name="LinkTitle"></FieldRef>
        
                    </ViewFields>
        
        .....
        

        这对我来说很好用!我的列表中还有一个名为 title 的列,但我的内容类型中没有任何名为 Title 的列,因此它在 newform、editform 和 viewform 页面中是隐藏的。

        【讨论】:

          【解决方案6】:

          您可以考虑在事件接收器中使用一些代码:

              private void HideTitleFormField(SPList list)
              {
                  SPContentTypeCollection listCTCollection = list.ContentTypes;
          
                  foreach (SPContentType ct in listCTCollection)
                  {
                      SPFieldLinkCollection fieldLinks = ct.FieldLinks;
          
                      //whilst we are here: hide the file name so it cant be edited.
                      fieldLinks["Title"].Hidden = true;
                      fieldLinks["Title"].Required = false;
          
                      ct.Update();          
                  }
              }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2010-09-08
            • 1970-01-01
            • 2021-09-18
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-02-14
            • 2020-04-03
            相关资源
            最近更新 更多