How to: Deploy Metadata Navigation Without Using Code

As someone who focuses mostly on ECM and Search, I am a huge fan of the new Metadata Navigation feature on document libraries in SharePoint 2010. It provides a great alternative to folders when it comes to navigating your document libraries. A list administrator can configure Metadata navigation on the document library settings page. However, I prefer to make changes using CAML or code so that I can deploy them easily to other environments. Usually, my first choice is with CAML, so I did some digging today and I discovered the trick to deploying your Metadata navigation settings using a SharePoint feature.

When I first started investigating this, I assumed it might be some new element or attribute inside the schema.xml file of the list. It turns out my assumption was incorrect. We actually set this by assigning some XML to the client_MOSS_MetadataNavigationSettings property on the root folder of the list. We can assign this value using code, but you know I prefer to use CAML. We can use the PropertyBag element to make this happen. Before we look at the PropertyBag element itself though, let’s look at the underlying XML. Let’s take my list here with three items selected for Metadata Navigation: a site column named DocumentType, the Content Type of the documents in the library, and the Folders in the library itself. Here is what the XML will look like.

The first line seems to always be the same. It enables the Metadata Navigation and it will take care of automatically adding new index columns when AutoIndex is set to true. The NavigationHierarchies section actually defines which fields will be used for Metadata navigation. If you want to navigate by folders, add a FolderHierarchy element and set HideFoldersNode to false. If you set it to true, folder navigation will not be present. The MetadataField element defines which fields to use for navigation. You need the GUID for each site column to include. You can get this from your list’s schema.xml file. You then need to specify the FieldType. Remember that it only supports Single-value Choice (Choice), Managed Metadata (TaxonomyFieldType) , and Content Type (ContentTypeId) field types. You then need to specify the field name in the CachedName field and then you can customize the display name as you see fit with CachedDisplayName. The last thing to note here is that you have to create a Managed Index for any choice fields you add. This is why you see a ManagedIndex element with the DocumentType field. Set the IndexId and IndexFieldId attributes equal to the Id of the field.

At this point, we are ready to assign this XML to the the client_MOSS_MetadataNavigationSettings property. We need to encode the above XML, because it is being stored inside an attribute of another XML document. Here is what your elements.xml file would look like.

It’s kind of hard to read the contents of the Property element, but it is just the encoded version of the XML above. As for the PropertyBag element, you just specify the relative Url to the document library on your site. In this case, it’s Shared Documents. Always set ParentType to Folder and RootWebOnly to false. At this point, you can activate this feature after you have deployed your document library and it will enable the Metadata navigation. Here is what the Metadata Navigation settings page looks like.

Here is what my document library looks like with the navigation enabled.

It’s pretty easy to set this up as you can see. Keep in mind that if you set this value, it will overwrite any values previously stored. This includes any Key Filters or Indexes that might already be present on the list.

Speaking of Key Filters, we can add them to the document library using the client_MOSS_MetadataNavigationSettings as well. Let’s look at some more XML. In this case, I am adding key filters for DocumentType, All Tags, and Modified By (editor).

The elements are pretty similar to that of the NavigationHierarchies element. You add one MetadataField element for each field you want with the same attributes as before. However, a few more fields types are supported such as Person or Group (User). It also recognizes Enterprise Keywords through the use of the All Tags (TaxonomyFieldMulti) filter. You can also do Date and Time fields as well as Number fields too. I also added the ManagedIndex field for Editor (the Modified By filter). You can probably leave the indexes out since AutoIndex is true, but if you run into issues, you can add them manually as you see above. You can deploy KeyFilters and NavigationHierarchies elements at the same time. You’ll need to encode the XML again just as you did before. When you activate the feature, you’ll have Key Filters enabled on your document library.

Using the PropertyBag element, you can easily add metadata navigation to your document libraries. This is a great alternative to defining these settings using code.

Corey Roth, a SharePoint Server MVP, is an independent consultant specializing in Cloud technologies such as Azure and Office 365. He also specializes in mobile development. Corey serves as the product manager for two cloud-first mobile app platforms: BrewZap and HappenZap.

Cloud Expo

Cloud Computing & All That
It Touches In One Location Cloud Computing - Big Data - Internet of Things
SDDC - WebRTC - DevOps
Cloud computing is become a norm within enterprise IT.

The competition among public cloud providers is red hot, private cloud continues to grab increasing shares of IT budgets, and hybrid cloud strategies are beginning to conquer the enterprise IT world.

Big Data is driving dramatic leaps in resource requirements and capabilities, and now the Internet of Things promises an exponential leap in the size of the Internet and Worldwide Web.

The world of SDX now encompasses Software-Defined Data Centers (SDDCs) as the technology world prepares for the Zettabyte Age.

Add the key topics of WebRTC and DevOps into the mix, and you have three days of pure cloud computing that you simply cannot miss.

Delegates will leave Cloud Expo with dramatically increased understanding the entire scope of the entire cloud computing spectrum from storage to security.

Cloud Expo - the world's most established event - offers a vast selection of 130+ technical and strategic Industry Keynotes, General Sessions, Breakout Sessions, and signature Power Panels. The exhibition floor features 100+ exhibitors offering specific solutions and comprehensive strategies. The floor also features two Demo Theaters that give delegates the opportunity to get even closer to the technology they want to see and the people who offer it.

Attend Cloud Expo. Craft your own custom experience. Learn the latest from the world's best technologists. Find the vendors you want and put them to the test.