【问题标题】:Access/Hide title-element访问/隐藏标题元素
【发布时间】:2012-06-03 11:08:07
【问题描述】:

我创建了一个从项目内容类型继承的内容类型。所以内容类型自动具有字段:标题。

但是如何访问这个字段(我想添加一些自定义验证并定义它是否显示在editform中)?

我想进行服务器端验证并使用自定义的 edititemform。也许有可能删除/隐藏此字段?

我已尝试更改内容类型以隐藏标题:

 <Field
  ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"
  Name="Title"
  StaticName="Title"
  DisplayName="Title"
  Type="Text"
  FromBaseType="TRUE"
  Required="FALSE"
  Hidden="TRUE"
  SourceID="http://schemas.microsoft.com/sharepoint/v3"
/>



  <!-- Parent ContentType: Element (0x01) -->
  <ContentType ID="0x0100b48c62c42879472aa8f1e1afc4dba7ce"
               Name="aa- aa"               
               Group="Custom Content Types"
               Description="My Content Type"
               Inherits="TRUE"
               Version="0">
      <FieldRefs>
        <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Hidden="TRUE" Required="FALSE" />

      </FieldRefs>

但标题字段仍然是必填项并显示。

【问题讨论】:

    标签: c# sharepoint sharepoint-2010 field content-type


    【解决方案1】:

    我发现了问题:

    如果我想隐藏以删除我的内容类型中的标题列,我必须禁用内容类型继承。但是在禁用 inharitation 后,自定义列将在部署后消失。因为它们不是基本类型的一部分。所以字段也必须在列表模式中声明。

    MSDN

    当 SharePoint Foundation 创建一个列表实例时,它只包括 在列表的基本类型架构中声明的那些列或 在列表架构中。如果您在列表中引用网站内容类型 架构,并且该内容类型引用了不属于 包含在列表的基本类型架构或列表架构中, 这些列不包括在内。您必须在 SharePoint Foundation 的列表架构以将它们包含在列表中。

    内容类型

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Field ID="{61CC6776-F855-48d5-A4EC-B7CE11CE2324}"
          DisplayName="ExpiresDate" Name="ExpiresDate"
          Type="DateTime" Required="False"
          UnlimitedLengthInDocumentLibrary="FALSE"/>
    
    
      <!-- Parent ContentType: Element (0x01) -->
      <ContentType ID="0x0100b48c62c42879472aa8f1e1afc4dba7ce"
                   Name="GroupsList - ContentTypeGroups"               
                   Group="Custom Content Types"
                   Description="My Content Type"
                   Inherits="false"
                   Version="0">
          <FieldRefs>
            <RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />
    
          <FieldRef ID="{61CC6776-F855-48d5-A4EC-B7CE11CE2324}" Name="ExpiresDate" Required="FALSE" ShowInNewForm="FALSE" ShowInEditForm="FALSE" />
          </FieldRefs>
      </ContentType>
    </Elements>
    

    列表架构

    ...
    
      <ContentTypes>
    
          <ContentTypeRef ID="0x0100b48c62c42879472aa8f1e1afc4dba7ce" />
        </ContentTypes>
        <Fields>
          <Field ID="{61CC6776-F855-48d5-A4EC-B7CE11CE2324}"
              DisplayName="ExpiresDate" Name="ExpiresDate"
              Type="DateTime" Required="False"
              UnlimitedLengthInDocumentLibrary="FALSE"/>
    
        </Fields>
    ...
    

    【讨论】:

      【解决方案2】:

      您无法隐藏内置标题字段,因为它基本上是唯一标识符,您需要显示它。但是,您可以rename your title field 这实际上被认为是最佳实践,应该这样做。

      【讨论】:

      • 你确定没有办法隐藏这个字段吗?我发现了一些对我不起作用的例子,但看起来其他人已经成功了。 social.technet.microsoft.com/Forums/en-US/…
      • 好吧,尝试使用那里描述的 FieldRef 方法,但通常你不应该隐藏标题列。
      猜你喜欢
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 2013-09-25
      • 2014-07-11
      相关资源
      最近更新 更多