| By Corey Roth | Article Rating: |
|
| March 24, 2011 12:30 PM EDT | Reads: |
1,824 |
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.
<MetadataNavigationSettings SchemaVersion="1" IsEnabled="True" AutoIndex="True">
<NavigationHierarchies>
<FolderHierarchy HideFoldersNode="False" />
<MetadataField FieldID="3c6f8f63-0616-437c-80eb-cf7cba0d88cc" FieldType="Choice" CachedName="DocumentType" CachedDisplayName="DocumentType" />
<MetadataField FieldID="03e45e84-1992-4d42-9116-26f756012634" FieldType="ContentTypeId" CachedName="ContentTypeId" CachedDisplayName="Content Type" />
</NavigationHierarchies>
<ManagedIndices>
<ManagedIndex IndexID="3c6f8f63-0616-437c-80eb-cf7cba0d88cc" IndexFieldName="DocumentType" IndexFieldID="3c6f8f63-0616-437c-80eb-cf7cba0d88cc" />
</ManagedIndices>
</MetadataNavigationSettings>
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.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<PropertyBag Url="Shared Documents" ParentType="Folder" RootWebOnly="FALSE" xmlns="http://schemas.microsoft.com/sharepoint/">
<Property Name="client_MOSS_MetadataNavigationSettings" Value="<MetadataNavigationSettings SchemaVersion="1" IsEnabled="True" AutoIndex="True"><NavigationHierarchies><FolderHierarchy HideFoldersNode="True" /><MetadataField FieldID="3c6f8f63-0616-437c-80eb-cf7cba0d88cc" FieldType="Choice" CachedName="DocumentType" CachedDisplayName="DocumentType" /> <MetadataField FieldID="03e45e84-1992-4d42-9116-26f756012634" FieldType="ContentTypeId" CachedName="ContentTypeId" CachedDisplayName="Content Type" /> </NavigationHierarchies><ManagedIndices><ManagedIndex IndexID="3c6f8f63-0616-437c-80eb-cf7cba0d88cc" IndexFieldName="DocumentType" IndexFieldID="3c6f8f63-0616-437c-80eb-cf7cba0d88cc" /><ManagedIndex IndexID="d31655d1-1d5b-4511-95a1-7a09e9b75bf2" IndexFieldName="Editor" IndexFieldID="d31655d1-1d5b-4511-95a1-7a09e9b75bf2" /></ManagedIndices></MetadataNavigationSettings>" Type="string" />
</PropertyBag>
</Elements>
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).
<MetadataNavigationSettings SchemaVersion="1" IsEnabled="True" AutoIndex="True">
<KeyFilters>
<MetadataField FieldID="3c6f8f63-0616-437c-80eb-cf7cba0d88cc" FieldType="Choice" CachedName="DocumentType" CachedDisplayName="DocumentType" />
<MetadataField FieldID="23f27201-bee3-471e-b2e7-b64fd8b7ca38" FieldType="TaxonomyFieldTypeMulti" CachedName="TaxKeyword" CachedDisplayName="All Tags" />
<MetadataField FieldID="d31655d1-1d5b-4511-95a1-7a09e9b75bf2" FieldType="User" CachedName="Editor" CachedDisplayName="Modified By" />
</KeyFilters>
<ManagedIndices>
<ManagedIndex IndexID="d31655d1-1d5b-4511-95a1-7a09e9b75bf2" IndexFieldName="Editor" IndexFieldID="d31655d1-1d5b-4511-95a1-7a09e9b75bf2" />
</ManagedIndices>
</MetadataNavigationSettings>
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.
Read the original blog entry...
Published March 24, 2011 Reads 1,824
Copyright © 2011 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Corey Roth
Corey Roth is a consultant at Stonebridge specializing in SharePoint for clients in the energy sector. He has more than ten years of experience delivering solutions in the energy, travel, advertising and consumer electronics verticals.
Corey specializes in delivering ECM and search solutions to clients using SharePoint. Corey has always focused on rapid adoption of new Microsoft technologies including Visual Studio 2010, .NET Framework 4.0, and Silverlight.
He is a member of the .NET Mafia (www.dotnetmafia.com) where he blogs about the latest technology and SharePoint. He is dedicated to the community and speaks regularly at user groups and SharePoint Saturdays.
- Microsoft Shows Off Win8 Tablet OS
- Microsoft to Collect More Android Royalties
- How to Start Unit Testing .NET Projects
- Book Review: Pro ASP.NET MVC 3 Framework
- Can PowerBuilder Leverage Mono?
- Book Review: Parallel Programming with Microsoft .NET
- PowerBuilder – Have Your Cake and Eat It Too
- Olympics Tickets Disappointment Likely To Lead To Holiday Booking Uplift
- Milliman als "Microsoft Technical and High-Performance Computing Partner" des Jahres 2011 ausgezeichnet
- La computación en nube abre nuevas posibilidades para la investigación del cáncer
- L'informatique en nuage avec Techila et Windows Azure ouvre de nouvelles possibilités à la recherche contre le cancer
- Microsoft Shows Off Win8 Tablet OS
- High-Profile Investor Wants Ballmer Out
- Microsoft to Collect More Android Royalties
- Book Review: The Art of Enterprise Information Architecture
- Silverlight Integration Pack for Microsoft Enterprise Library 5.0
- Book Review: UML 2 and the Unified Process
- Book Review: Microsoft Expression Blend Unleashed
- Book Review: Practical Code Generation in .NET
- Microsoft – Where Will It Be in Ten Years?
- Book Review: Essential SharePoint 2010: Overview, Governance, & Planning
- Book Review - Enterprise Model Patterns: Describing the World
- How to Start Unit Testing .NET Projects
- Where Are RIA Technologies Headed in 2008?
- Accessing the ASP.NET Authentication, Profile and Role Service in Silverlight
- The Top 250 Players in the Cloud Computing Ecosystem
- Building Great AJAX Applications Using ASP.NET
- Silverlight 2 - Adobe Flex Killer Is on Its Way!
- Spice Up User Experience with Silverlight
- Is the Silverlight Adoption Rate Artificially Inflated?
- Will Google's Android Sink or Swim?
- Kaazing Announces Support for Silverlight
- The Next Chapter in the Virtualization Story Begins
- Rich Content Rotator for ASP.NET
- Getting Started with Silverlight: Zero to Hero

































