託管元數據字段未與VS解決方案創建的自定義列表中的網站列相關聯


1

這裡,我在Visual Studio中創建了自定義託管元數據列,如下所示。

 <Field
           Type="TaxonomyFieldTypeMulti"
           DisplayName="Document Type"
           StaticName="DocumentType"
           Name="DocumentType"
           Group="ManagedMetaData"
           ShowField="Term1033"
           Description="Managed Metadata for the Document Type."
           Required="FALSE"
           EnforceUniqueValues="FALSE"
           ID="{8B2F26F1-9A2B-41E5-BFC3-63D9CB4A7703}"
           DisplaceOnUpgrade="TRUE"
           Overwrite="TRUE"
           Mult="FALSE">
    <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">{28226668-3DDE-46F2-875B-CA7A873A468E}</Value>
        </Property>
      </ArrayOfProperty>
    </Customization>
  </Field>

我將其包含在"內容類型"中,並將此內容類型綁定到自定義列表(此處我正在創建日曆列表)。

,還有一些我要添加到事件接收器的c#代碼。如下。

 string groupName = "groupName";
        Dictionary<string, string> termDictionary = new Dictionary<string, string> { { "Document Type", "{8B2F26F1-9A2B-41E5-BFC3-63D9CB4A7703}" } };
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb currentSite = null;
            if (properties.Feature.Parent is SPWeb)
            {
                currentSite = (SPWeb)properties.Feature.Parent;
            }
            else if (properties.Feature.Parent is SPSite)
            {
                currentSite = ((SPSite)properties.Feature.Parent).RootWeb;
            }
            if (currentSite != null)
            {
                CreateGroupTermSet(currentSite);
                foreach (var termItem in termDictionary)
                {
                    AssociateMetadata(currentSite, new Guid(termItem.Value), termItem.Key);
                }
            }
            currentSite.Close();
        }

        private void CreateGroupTermSet(SPWeb currentSite)
        {
            TaxonomySession ts = new TaxonomySession(currentSite.Site);
            TermStore termStore = ts.TermStores[0];
            if (!termStore.Groups.Any(g => g.Name == groupName))
            {
                Group group = termStore.CreateGroup(groupName);
                foreach (var termName in termDictionary)
                {
                    if (!group.TermSets.Any(g => g.Name == termName.Key))
                    {
                        TermSet termSetDepartment = group.CreateTermSet(termName.Key);
                        termSetDepartment.IsOpenForTermCreation = true;
                    }
                }
            }
            termStore.CommitAll();
        }

        private void AssociateMetadata(SPWeb currentSite, Guid fieldId, string termSetName)
        {
            if (currentSite.Site.RootWeb.Fields.Contains(fieldId))
            {
                TaxonomySession session = new TaxonomySession(currentSite.Site);

                TermStoreCollection termStores = session.TermStores;
                if (session.TermStores.Count != 0)
                {
                    var termStore = session.TermStores["Managed Metadata Service"];

                    var termGroup = termStore.Groups[groupName];
                    var termSet = termGroup.TermSets[termSetName];

                    TaxonomyField field = currentSite.Site.RootWeb.Fields[fieldId] as TaxonomyField;

                    field.SspId = termSet.TermStore.Id;
                    field.TermSetId = termSet.Id;
                    field.TargetTemplate = string.Empty;
                    field.AnchorId = Guid.Empty;
                    field.CreateValuesInEditForm = true;
                    field.Open = true;
                    field.Update();
                }
            }
        }

完成所有這些工作後,我只是在網站集上部署了此解決方案,我試圖在列表中添加該術語,但是該字段已被禁用,這不允許我輸入term。那看起來像下面的快照。enter image description here

但是在這裡,如果我在網站集中手動創建任何其他列表並將相同的內容類型分配給它,那麼我可以在其中添加此data.you可以在下面的快照中看到。enter image description here所以在這裡我無法像我做錯什麼一樣去解決它

0

You should check te sequence how the list is created. First deploy site columns and contenttypes to your site using a different feature with an event receiver to set the tax field. In different feature add the list to your site.


1

Resolved the Issue by Adding the note filed to that metadata column as like below and Adding the same Note field column to the List.

<Field
           Type="TaxonomyFieldTypeMulti"
           DisplayName="Document Type"
           StaticName="DocumentType"
           Name="DocumentType"
           Group="ManagedMetaData"
           ShowField="Term1033"
           Description="Managed Metadata for the Document Type."
           Required="FALSE"
           EnforceUniqueValues="FALSE"
           ID="{8B2F26F1-9A2B-41E5-BFC3-63D9CB4A7703}"
           DisplaceOnUpgrade="TRUE"
           Overwrite="TRUE"
           Mult="FALSE">
    <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">{28226668-3DDE-46F2-875B-CA7A873A468E}</Value>
        </Property>
      </ArrayOfProperty>
    </Customization>
  </Field>
 <Field Type="Note"
           DisplayName="DocumentType_0"
           StaticName="DocumentTypeTaxHTField0"
           Name="DocumentTypeTaxHTField0"
           ID="{28226668-3DDE-46F2-875B-CA7A873A468E}"
           ShowInViewForms="FALSE"
           Required="FALSE"
           Hidden="TRUE"
           CanToggleHidden="TRUE"
           Group="ManagedMetaData"
           RowOrdinal="0"
    />