{"id":1284,"date":"2014-05-15T11:22:18","date_gmt":"2014-05-15T11:22:18","guid":{"rendered":"https:\/\/poiseddevelopers.com\/reality-tech\/?p=1284"},"modified":"2024-04-26T12:37:27","modified_gmt":"2024-04-26T12:37:27","slug":"programmatically-configuring-metadata-navigation","status":"publish","type":"post","link":"https:\/\/poiseddevelopers.com\/reality-tech\/programmatically-configuring-metadata-navigation\/","title":{"rendered":"Programmatically Configuring Metadata Navigation"},"content":{"rendered":"<p>Metadata navigation offers a quite clever way to navigate documents within a library. It cuts across folders, and allows drill-in for taxonomies as configured hierarchies, and also allows for a combination of fields for key filters. One can configure it manually for a library, but how can one do this programmatically? Below are the steps:<\/p>\n<pre lang=\"php\">\r\n# get the SPWeb:\r\n$web = Get-SPWeb \"http:\/\/WhateverTheSPWebSiteIs\"\r\n \r\n# get the library:\r\n$JPLib = $web.Lists.TryGetList(\"WhateverTheListIsCalled\")\r\n \r\n# Here's the XML object we are coding against:\r\n$listNavSettings = [Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationSettings]::GetMetadataNavigationSettings($JPLib)\r\n \r\n# You can output the XML settings and easily see its configuration each step along the way with this:\r\n$listnavSettings.SettingsXml\r\n \r\n# Here's how to clear both Configured Hierarchies, and Key Filters:\r\n$listNavSettings.ClearConfiguredHierarchies()\r\n$listNavSettings.ClearConfiguredKeyFilters()\r\n[Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationSettings]::SetMetadataNavigationSettings($JPLib, $listNavSettings, $true)\r\n \r\n# Let's get ready for a Content Type Hierarchy\r\n$ctHierarchy = [Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationHierarchy]::CreateContentTypeHierarchy()\r\n$listnavSettings.AddConfiguredHierarchy($ctHierarchy)\r\n \r\n# Add a configured Hierarchy:\r\n$listNavSettings.AddConfiguredHierarchy($JPLib.Fields[\"Field Name\"])\r\n \r\n# Add a Content Type Key Filter; I chose this on purpose, as using \"Content Type\" will not work, the field to use here is \"Content Type ID\":\r\n$listNavSettings.AddConfiguredKeyFilter($JPLib.Fields[\"Content Type ID\"])\r\n \r\n# Now the party ends happily with an update; note no $list.update() or $web.update() is needed:\r\n[Microsoft.Office.DocumentManagement.MetadataNavigation.MetadataNavigationSettings]::SetMetadataNavigationSettings($JPLib, $listNavSettings, $true)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Metadata navigation offers a quite clever way to navigate documents within a library. It cuts across folders, and allows drill-in for taxonomies as configured hierarchies, and also allows for a combination of fields for key filters. One can configure it manually for a library, but how can one do this programmatically? Below are the steps: [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":1288,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[26],"tags":[],"class_list":["post-1284","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"_links":{"self":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/comments?post=1284"}],"version-history":[{"count":3,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1284\/revisions"}],"predecessor-version":[{"id":1291,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/1284\/revisions\/1291"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media\/1288"}],"wp:attachment":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media?parent=1284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/categories?post=1284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/tags?post=1284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}