Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Im running SP 2013 with VS 2012 on a MS 2012 server. I want to create a list, with one colum type called "Managed Metada". Via settings -> create column in IE there is no problem. But, when I create a list in VS there is no option for managed metadata.

Internet explorer view: Add column via Internet Explorer

Visual studio view: Visual Studio view

Why is this optin in Visual studio missing?

is there any possible way to do this via VS?

thanks

share|improve this question

2 Answers 2

up vote 3 down vote accepted

managed meta data column is quite complexe. It consists of two fields: Taxonomy field and note field. Plus you have to connect your taxonomy field to managed metadata store and it is quite tricky. So I think there was a reason why Microsoft did not include this column to create...

What we usually do is to create a content type with both definitions of Taxonomy and Taxonomy Note fields. Apply this content type to list and attach the field to MMS terms and/or tags.

Once you create list ths column appears well as "TaxonomyFieldType"

enter image description here

Hope it helps,

Andrew

share|improve this answer
    
Thanks for the answer, but what are exactly the definitions of taxonomy and taxonomy note fields ? I do not find them when I create a new content type. –  Jürgen Stürmer Mar 6 '13 at 13:46
    
Actually these fields you see on my picture are custom content type fields. When I have created content type holding these fields and added this content type to document library they are appeard itself from content type definition. Do you have you custom content type? What I suggets you is to add MMS field to content type (any you use) and recreate your list based on this content type. This should appear now... –  Andrew Adamich Mar 6 '13 at 13:49
    
I followed this tutorial (link ) from Creating fields and content types. I hoped to find the custom fields you mentioned before. –  Jürgen Stürmer Mar 6 '13 at 13:54
    
Here is a post how you can do this: sharepointconfig.com/2011/03/…. To edit XML file just double click on elemet.xml and hit yes when VS will ask about closing designer... –  Andrew Adamich Mar 6 '13 at 14:14
    
Thanks, that link helps a lot :) –  Jürgen Stürmer Mar 6 '13 at 14:35

I use the following piece of code for that:

string TermStoreName = "Managed Metadata Service";
TaxonomySession session = new TaxonomySession(web.Site);
if (session.TermStores.Count == 0)
{
    return;
}

var termStore = session.TermStores[TermStoreName];
if (!web.Fields.ContainsField(fieldName))
{
    var group = from g in termStore.Groups where g.Name == "MainCollection" select g;
    var termSet = group.FirstOrDefault().TermSets[metadataName];

    //Create a new TaxonomyField

    TaxonomyField field = web.Fields.CreateNewField("TaxonomyFieldType", fieldName) as TaxonomyField;

    field.SspId = termSet.TermStore.Id;
    field.TermSetId = termSet.Id;
    field.TargetTemplate = string.Empty;
    field.AllowMultipleValues = true;
    field.CreateValuesInEditForm = true;
    field.Open = true;
    field.AnchorId = Guid.Empty;
    field.Group = SiteColumnsGroup;

    //Add the taxonomy field to site columns
    string internalName = web.Fields.Add(field);
    web.Update();

    SPField spField = web.Fields[fieldName];
    contentType.FieldLinks.Add(new SPFieldLink(spField));
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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