2 March 2011
You can provision managed metadata column into the content type.
You need to add the “Metadata” column into the site columns and content type using element xml file, and also need to connect the field to metadata column in the feature activation.
Here is the solution
1. You need to add a new field element of the type “TaxonomyFieldType”.
<xml version="1.0" encoding="utf-8" ?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Field ID="{46138ADB-1778-4E05-8371-114006F725A0}" Type="TaxonomyFieldType" DisplayName="Locations" ShowField="Term1033" Required="TRUE" EnforceUniqueValues="FALSE" Group="_Custom" StaticName="Locations" Name="Locations" /> </Elements>
2. Add this filed to the content type, just need to add a new “FieldRef”
<FieldRef ID="{46138ADB-1778-4E05-8371-114006F725A0}" Name="Locations"/>
3. Now we have to connect this field to managed metadata service(MMS).
For this we need to create an event receiver for the feature. Right click on the feature
and select “Add event receiver”.
Uncomment the “feature activate” code and replace it with the following code.
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; Guid fieldId = new Guid(“{46138ADB-1778-4E05-8371-114006F725A0}" if (site.RootWeb.Fields.Contains(fieldId)) { TaxonomySession session = new TaxonomySession(site); if (session.TermStores.Count != 0) { var termStore = session.TermStores["Managed Metadata Service"]; var group = termStore.Groups.GetByName("Locations Group"); var termSet = group.TermSets["Towns"]; TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField; field.SspId = termSet.TermStore.Id; field.TermSetId = termSet.Id; field.TargetTemplate = string.Empty; field.AnchorId = Guid.Empty; field.Update(); } } }
This method will check if the field has been deployed. We used Guid to retrieve the filed as defined in the XML. Your term store group definition should look like this.
If it is different then you need to change the “group name” and “term set” name in the feature activation according to your MMS environment.
Now you deploy your content type and can test it by creating a new list from that content type.
The result with the metadata column is shown in the below picture.
New Jordans 2011
dads happen to be skeptics or possibly Deists; individuals actually made a fabulous secular governing by "unbreachable wall" approximately house of worship and additionally assert; individuals still gave them throughout the treaty along with the Moslem location about Tripoli a right announcement which usually, nothing like The european union, all the "United State governments isn’t really, in any meaning, a fabulous Stacee location. " (So finally appreciated was first all the precept about separation about house of worship and additionally assert just of the fact that treaty went by Our lawmakers with very little discourse relating to which usually terms, and additionally Chief executive Tom Adams fixed the software instantly, with very little terror that hot weather will probably put at risk an individual’s politics long term future. )
Chris OConnor
Brilliant post – this is exactly what I was needing – thanks !
I’m now have a feature that adds a bunch of columns – including the termset column – cheers !! 🙂
Aziz
You are welcome Chris 🙂
Regards
Rashid Aziz