I've been looking online at a bunch of MSDN examples of how to programmatically build and then set Metadata Navigation through feature recievers. The sample code MSDN gives you is as follows:

NavigationTermSet navTermSet = NavigationTermSet.GetAsResolvedByWeb(termSet, web,

navTermSet.IsNavigationTermSet = true;
navTermSet.TargetUrlForChildTerms.Value = "~site/Pages/Topics/Topic.aspx";

NavigationTerm term1 = navTermSet.CreateTerm("Term 1", NavigationLinkType.SimpleLink);
term1.SimpleLinkUrl = "http://www.bing.com/";

NavigationTerm term2 = navTermSet.CreateTerm("Term 2", NavigationLinkType.FriendlyUrl);
NavigationTerm term2a = term2.CreateTerm("Term 2 A", NavigationLinkType.FriendlyUrl);
NavigationTerm term2b = term2.CreateTerm("Term 2 B", NavigationLinkType.FriendlyUrl);

NavigationTerm term3 = navTermSet.CreateTerm("Term 3", NavigationLinkType.FriendlyUrl);

As a simple example. This is nice, however I can't fully comprehend how the FriendlyUrl terms work. For instance, how do I set a custom FriendlyURL path (such as /community-blog) for a term? How do I set the path the term should re-direct you to (such as ~site/blog/CustomHomePage.aspx)? I want to utilize the friendly URL naming but can't figure it out from what's documented on MSDN. Has anyone figured it out? As a workaround, I'm currently creating all SimpleLinks and setting their SimpleLinkUrl property, but that doesn't let you set a custom friendly URL as far as I know.

1 Answer 1


It took me a bit of discovery, but I figured out that there are some values you can actually edit for NavigationLinkType.FriendlyUrl. Microsoft doesn't have any documentation that shows how you can edit them. Below is an example that will show better than I can explain:

NavigationTerm term = navigationTermSet.CreateTerm("Communities", NavigationLinkType.FriendlyUrl, Guid.NewGuid());
term.FriendlyUrlSegment.Value = "communities";
term.TargetUrl.Value = "~site/Communities/";

The key here is that FriendlyUrlSegment and TargetUrl are CustomizableString types. I'm not sure what assembly defines that type, but you need to dig into the value property of a CustomizableString to be able to modify it. I had simply assumed that these were locked off because term.FriendlyUrlSegment = "communities"; would not run.

There are a few caveats I've found with these properties:

  • FriendlyUrlSegment.Value must not contain slashes (/\).
  • TargetUrl.Value must lead to a web page. For instance, you cannot use ~site to bring you to the home page of the site, although you can if you manually create a friendly navigation term through the Term Store Manager.
  • TargetUrl.Value must lead to a page in the current site (SPWeb).
  • You can reuse the same NavigationTerm item. If you were to take the first three lines of the code above and put them into a loop the term variable will always refer to a new term everytime you call CreateTerm.

Once that is all figured out though, you can deploy a nice, clean set of metadata navigation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.