We have our own type of content in our SharePoint 2010 build that includes the Managed Metadata field for keywords.
The field seems to be expanded OK, because if I edit the item in the list it is in, I get the correct taxonomy selection control and my conditions are retrieved from the term store.
Nonetheless; we use the EditModePanel on the Layout page for the item to allow in-place editing of the objects, and I cannot get the correct taxonomy selection control.
If I add TaxonomyWebTaggingControl to the page layout and hardcode SSPId etc., then it will work;
<TaxonomyControls:TaxonomyWebTaggingControl runat="server" SSPId="234234-234234-34341-343" TermSetId="234234-23342-34234-234-234"/>
However, we cannot hard code the values, since the term repository will be created when the client deploys the site.
When we create a content type, we have an event receiver that binds the field to the correct storage / term set using their names, but I donβt understand how to get the field in EditModePanel to get / set them.
What I really want is something like:
<TaxonomyControls:TaxonomyWebTaggingControl runat="server" TermStore="My term store name" TermSet="Keywords"/>
Did I miss something?
My event receiver is as follows:
try
{
SPSite site = ((SPWeb)properties.Feature.Parent).Site as SPSite;
Guid fieldId = new Guid("3211B052-5332-424C-A066-BBE21AEAB878");
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("My Client");
var termSet = group.TermSets["Keywords"];
TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;
field.SspId = termSet.TermStore.Id;
field.TermSetId = termSet.Id;
field.AnchorId = Guid.Empty;
field.AllowMultipleValues = true;
field.TextField = fieldId;
field.TextField = new Guid("{574C5BCE-74E8-40C8-BE90-C9338135D491}");
field.Update();
Log.Logger.LogEvent("ContentType Activation", "Updated keywords field with MMS details");
}
}
}
catch (Exception ex)
{
Log.Logger.LogException(ex, "Content Type Activation", ex.Message);
}