Manage Metada fields – Link to Categories.aspx Page

Have you been creating custom manage metadata fields while working on Wiki Site? Have you observed that tags that you create as part of these custom fields do not show link to categories.aspx.

If you observe an out of the box Wiki Categories manage metadata field, it comes with a hyperlink on tags that navigates to a page called ‘Categories.aspx’. This is really a handy feature where you can see the pages with the tag that you clicked. But when it comes to custom manage metadata tag, this option is not available. Hmm.. What a bother !!

Well !!! Fortunately there is a way to fix this. It is basically a problem with a property called ‘TargetTemplate’ on the metadata field that is not set out of the box.  Using a CSOM code you can override this property and set the URL… Below is the code…

static void Main(string[] args)
{
UpdateTaxonomyProperties(“<Name of Manage MetadaField>”);
//GetTaxonomyProperties(“Wiki Categories”);
}
public static void UpdateTaxonomyProperties(string fieldName)
{
using (ClientContext Context = new ClientContext(ConfigurationManager.AppSettings[“SiteURL”].ToString()))
{
Context.Credentials = new SharePointOnlineCredentials(ConfigurationManager.AppSettings[“UserId”].ToString(), GetSecureString(ConfigurationManager.AppSettings[“Password”].ToString()));
Web oWeb = Context.Web;
Context.Load(oWeb);
Context.ExecuteQuery();
Field field = oWeb.Fields.GetByInternalNameOrTitle(fieldName);
TaxonomyField taxonomyField = Context.CastTo<TaxonomyField>(field);
taxonomyField.TargetTemplate = “_layouts/15/Categories.aspx”;
taxonomyField.Update();
Context.Load(taxonomyField);
Context.ExecuteQuery();
}
}
public static void GetTaxonomyProperties(string fieldName)
{
using (ClientContext Context = new ClientContext(ConfigurationManager.AppSettings[“SiteURL”].ToString()))
{
Context.Credentials = new SharePointOnlineCredentials(ConfigurationManager.AppSettings[“UserId”].ToString(), GetSecureString(ConfigurationManager.AppSettings[“Password”].ToString()));
Web oWeb = Context.Web;
Context.Load(oWeb);
Context.ExecuteQuery();
Field field = oWeb.Fields.GetByInternalNameOrTitle(fieldName);
TaxonomyField taxonomyField = Context.CastTo<TaxonomyField>(field);
Context.Load(taxonomyField);
Context.ExecuteQuery();
}
}
public static SecureString GetSecureString(string input)
{
SecureString output = new SecureString();
foreach (char c in input.ToCharArray()) output.AppendChar(c);
return output;
}

 

 

Leave a comment