Is there any way to set a default value for a site-column of type managed metadata in SharePoint 2010 programmatically using C#?

I have come accross the following code, however, it throws "array out of bound..." error for wssId.

 TermSet termSet = null;
            Term term = null;
            TaxonomySession currentSession = new TaxonomySession(newBuiltSite);
            var termStore = currentSession.TermStores["Managed Metadata Service"];
            var group = termStore.Groups["Code Group"];
            termSet = group.TermSets["Code"];
            term = termSet.Terms[siteCode];
            int[] wssId = TaxonomyField.GetWssIdsOfTerm(newBuiltSite, termStore.Id, termSet.Id, term.Id, false, 1);
            TaxonomyField field = newBuiltSite.RootWeb.Fields["Code"] as TaxonomyField;
            field.SspId = termSet.TermStore.Id; // termStore.Id;
            field.TermSetId = termSet.Id;
            field.TargetTemplate = string.Empty;
            field.AnchorId = Guid.Empty;
            field.DefaultValue = wssId[0].ToString() + ";#" + term.Name + "|" + term.Id.ToString().ToLower();

1 Answer 1


Once you map the site column to term set, edit the site column to set its default value.

enter image description here

  • Thanks for your reply, Deepmala! However, I need to do it programmatically using C#, sorry for not posing my questing clearly, I have just updated my question.
    – Rajiv
    Mar 7, 2018 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.