We have a custom content type in our SharePoint 2010 build which includes a Managed Metadata field for keywords.
The field seems to have deployed OK because if I edit an item in the list in which it resides I get the correct Taxonomy picker control and my terms are retrieved from the term store.
However; we are using an EditModePanel on the PageLayout for the item to allow in-site editing of the items and I can't get the correct Taxonomy picker control to appear.
If I add a TaxonomyWebTaggingControl to the page layout and hardcode the SSPId etc then it works;
<TaxonomyControls:TaxonomyWebTaggingControl runat="server" SSPId="234234-234234-34341-343" TermSetId="234234-23342-34234-234-234"/>
However we can't hardcode the values as the term store will be created when the client deploys the site.
When we create the Content type we have an Event Receiver which binds the field to the correct Term Store/Set using their names but I don't understand how to get a field in the EditModePanel to get/set these.
What I really want is something like:
<TaxonomyControls:TaxonomyWebTaggingControl runat="server" TermStore="My term store name" TermSet="Keywords"/>
Am I missing something?
My event receiver looks like this:
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);
}
You should use the TaxonomyFieldControl for this:
<%@ Register Tagprefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<Taxonomy:TaxonomyFieldControl FieldName="My Field Name" runat="server" id="myField"/>