SharePoint: Create managed metadata field programatically

The following piece of code creates a managed metadata column with internal name "BusinessLocation" and display name "Business Location"

using (SPSite site = new SPSite("http://intranet.contoso.com/sites/contracts"))
{
    using (SPWeb web = site.OpenWeb())
    {                  
        TaxonomySession taxonomySession = new TaxonomySession(site);
        TermStore termStore = taxonomySession.TermStores["Managed Metadata Service"];
        Group group = termStore.Groups["Corporate Taxonomy"];
        TermSet termset = group.TermSets["Geography"];
        TaxonomyField taxonomyField = web.Fields.CreateNewField("TaxonomyFieldType", "BusinessLocation") as TaxonomyField;
        taxonomyField.Description = "Loction of business house.";
        taxonomyField.SspId = termStore.Id;
        taxonomyField.TermSetId = termset.Id;
        taxonomyField.AllowMultipleValues = false;
        taxonomyField.Group = "My Content Types";
        web.Fields.Add(taxonomyField);
        TaxonomyField field = site.RootWeb.Fields["BusinessLocation"] as TaxonomyField;
        field.Title = "Business Location";
        field.Update(true);
    }
}
profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+