2

I have added document library template using VS 2012. and then added custom content types to this library. the content types includes 3 managed metadata fields. After deploying the project when I add terms to taxonomy fields in document library, I got following error:

"The SPListItem being updated was not retrieved with all taxonomy fields"

I could not find any solution. Any body have an idea whats wrong ?

4

1 回答 1

2

在内容类型的 ELEMENTS.XML 文件中,您的字段(实际上您需要两个,注意它们是如何链接在一起的)必须类似于:

<Field Type="Note"
     ID="{4B53F593-CF60-40DF-AEAF-23155BB9AA3F}"
     DisplayName="_Circular_Tags"
     Name="Circular_Tags_NOTE"
     StaticName="Circular_Tags_NOTE"
     ShowInViewForms="FALSE"
     Required="FALSE"
     Hidden="TRUE"
     CanToggleHidden="TRUE"
     RowOrdinal="0">
  </Field>
  <Field Type="TaxonomyFieldTypeMulti"
     ID="{DF553026-F699-456F-AA24-0C6087DBE885}"
     Name="Circular_Tags"
     StaticName="Circular_Tags"
     DisplayName="Circular_Tags_DisplayName"
     Description="Circular_Tags_Description"
     ShowField="Circular_Tags_Path"
     Required="FALSE"
     Sortable="FALSE"
     AllowDeletion="TRUE"
     EnforceUniqueValues="FALSE"
     ShowInViewForms="TRUE"
     Group="MyContentTypes_Group">
    <Default></Default>
    <Customization>
      <ArrayOfProperty>
        <Property>
          <Name>TextField</Name>
          <Value xmlns:q6="http://www.w3.org/2001/XMLSchema" p4:type="q6:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{4B53F593-CF60-40DF-AEAF-23155BB9AA3F}</Value>
        </Property>
      </ArrayOfProperty>
    </Customization>
  </Field>

然后您需要(在功能激活代码中)执行以下操作:

 SPSite site = properties.Feature.Parent as SPSite;
Guid fieldId = new Guid("{DF553026-F699-456F-AA24-0C6087DBE885}");
if (site.RootWeb.Fields.Contains(fieldId))
{
    TaxonomySession session = new TaxonomySession(site);
    if (session.TermStores.Count != 0)
    {
        var termStore = session.TermStores["ManagedMetadata_Proxy"];
        var group = termStore.Groups["GroupName"];
        var termSet = group.TermSets["TermSetName"];
        TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;

        //set the text field to the id of the _Circular_Tags field : 4B53F593-CF60-40DF-AEAF-23155BB9AA3F
        field.TextField = new Guid("{4B53F593-CF60-40DF-AEAF-23155BB9AA3F}");

        // Connect to MMS
        field.SspId = termSet.TermStore.Id;
        field.TermSetId = termSet.Id;
        field.TargetTemplate = string.Empty;
        field.AnchorId = Guid.Empty;
        field.Update();
    }
}

最后,在列表定义中的 SCHEMA.XML 文件中,您应该为该字段提供如下定义:

<Field Type="TaxonomyFieldType" ID="{DF553026-F699-456F-AA24-0C6087DBE885}" Name="Circular_Tags" StaticName="Circular_Tags" DisplayName="Circular_Tags_DisplayName" Description="Circular_Tags_Description" ShowField="Circular_Tags_Path" Mult="TRUE" Required="FALSE" Sortable="FALSE" AllowDeletion="TRUE" EnforceUniqueValues="FALSE" ShowInViewForms="TRUE" Group="ContentTypes_Group">
        <Default></Default>
        <Customization>
          <ArrayOfProperty>
            <Property>
              <Name>TextField</Name>
              <Value xmlns:q6="http://www.w3.org/2001/XMLSchema" p4:type="q6:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{4B53F593-CF60-40DF-AEAF-23155BB9AA3F}</Value>
            </Property>
          </ArrayOfProperty>
        </Customization>
      </Field>
于 2013-09-11T10:42:38.600 回答