Wednesday, April 23, 2014

Deploy Metadata Navigation through CAML - NO CODE Approach

Hey,

The requirements was to create a new List Instance using CAML approach with some Metadata Navigation Settings pre-configured into it as in my list I have used a Managed Metadata Field.

This turned out to be harder than I thought !!!

After Googling I came to the post by Corey Roth which help understand the concept of MetadataNavigationSettings used as a CAML.

Now, where to find the Value of  client_MOSS_MetadataNavigationSettings  Property, I tried to rebuild the CAML manually using the common sense and doing some trial and error with the MetadataField FieldID GUID however it wasn't working...

Thereafter, I decided to get the value programmatically - for that I created a dummy Document Library and I got the XML Value of the client_MOSS_MetadataNavigationSettings using the below code and VOILA - I got the value.
SPDocumentLibrary lib = (SPDocumentLibrary)site.OpenWeb().Lists["SharedDocuments"];var res = lib.RootFolder.Properties["client_MOSS_MetadataNavigationSettings"];
Once I got the value, I converted the XML tag into HTML - These 3 symbols only:
" by "
< by &lt;
> by &gt;
Finally, my Elements.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance FeatureId="{00bfea71-e717-4e80-aa17-d0c71b360101}" TemplateType="101" Title="MyDocuments" Description="" Url="MyDocuments" CustomSchema="Files\MyDocuments\Schema.xml" HyperlinkBaseUrl="http://zin506/sites/TeamSite" RootWebOnly="FALSE" xmlns="http://schemas.microsoft.com/sharepoint/"  OnQuickLaunch="TRUE" />
  <PropertyBag Url="MyDocuments" ParentType="Folder" RootWebOnly="FALSE" xmlns="http://schemas.microsoft.com/sharepoint/">
    <Property Name="client_MOSS_MetadataNavigationSettings" Type="string"
              Value="&lt;MetadataNavigationSettings SchemaVersion=&quot;1&quot; IsEnabled=&quot;True&quot; AutoIndex=&quot;True&quot;&gt;
  &lt;NavigationHierarchies&gt;
    &lt;FolderHierarchy HideFoldersNode=&quot;True&quot; /&gt;
    &lt;MetadataField FieldID=&quot;7ced7787-dcf6-4748-a23e-f0248f89db58&quot;
                   FieldType=&quot;TaxonomyFieldType&quot;
                   CachedName=&quot;Category&quot;
                   CachedDisplayName=&quot;Category&quot; /&gt;
  &lt;/NavigationHierarchies&gt;
  &lt;KeyFilters /&gt;
&lt;/MetadataNavigationSettings&gt;" />
  </PropertyBag>
</Elements>

Enjoy! 

No comments:

Post a Comment