3

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);
        }
Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
Andy Todd
  • 63
  • 1
  • 5

1 Answers1

3

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"/>

  • I've amended my Page layout to use the TaxonomyFieldControl but it appears disabled/greyed out and clicking on the tag icon does nothing? – Andy Todd Feb 11 '11 at 17:19
  • It seems to be - I've added the code for my event receiver in the original post. I've stepped through this in the debugger and it doesn't error. – Andy Todd Feb 14 '11 at 13:28
  • I've got it working now - I deleted my site and re-created it which obviously refreshed the library columns. The only snag is that the MM column does not get automatically added to the library columns, I have to manually add it. – Andy Todd Feb 15 '11 at 15:59