how to create taxonomyField with genesis

        [SPGENField(
            ID = "{BADCE114-FB99-4F27-A777-030E336D1EFA}",
            StaticName = "MMDSubject",
            InternalName = "MMDSubject",
            DisplayName = "$Resources:Model,Field_MMDSubject_DisplayName;",
            CustomType = "TaxonomyFieldType",
            Group = "$Resources:Model,FieldGroup_Title;")]
        public class MMDSubject : SPGENField<MMDSubject, TaxonomyField, TaxonomyFieldValue>
        {
            protected override void OnProvisionFinalized(TaxonomyField field, SPFieldCollection fieldCollection, bool isParentList, bool updatedOnly)
            {
                SPSite site = fieldCollection.Web.Site;
                SPWeb rootWeb = site.RootWeb;

                TaxonomySession session = new TaxonomySession(site);
                TermStore termStore = session.TermStores["MMD"];

                Group group_TaxTest = termStore.Groups["Root"];
                TermSet ts_TaxTest = group_cbsTaxTest.TermSets["נושאים"];

                field.SspId = termStore.Id;
                field.TermSetId = ts_TaxTest.Id;
                field.TargetTemplate = string.Empty;
                //cbsTaxTest.AllowMultipleValues = true;
                field.CreateValuesInEditForm = true;
                field.Open = true;
                //cbsTaxTest.IsAnchorValid = true;
                field.AnchorId = Guid.Empty;
                field.Update();
                base.OnProvisionFinalized(field, fieldCollection, isParentList, updatedOnly);
            }
        }

if you need it as a multi dont forget to use multi class: TaxonomyFieldValueCollection

Comments

Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

JS/JQ simulate Enter event

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem