Does anyone know how to add only one custom MetadataNavigationHierarchy
?
In my case, I would like to remove Folders from the TreeView, so my custom MetadataNavigationHierarchy
is the only one being displayed.
I'm currently working on a Console application that's setting up Metadata navigation on an existing SharePoint 2013 document library containing existing folders and files.
Everything is working as it's supposed to, but I would like to remove Folders from the navigation.
Working code I use to add my custom value Tema:
MetadataNavigationSettings mdnSettings = MetadataNavigationSettings.GetMetadataNavigationSettings(list);
if (taxonomyField != null)
{
MetadataNavigationHierarchy hierarchyToAdd = new MetadataNavigationHierarchy(taxonomyField);
if (null == mdnSettings.FindConfiguredHierarchy(taxonomyField.TermSetId))
{
mdnSettings.AddConfiguredHierarchy(hierarchyToAdd);
}
}
else
{
Helper.WriteError("Could not find Tema taxonomy field");
}
MetadataNavigationSettings.SetMetadataNavigationSettings(list, mdnSettings, true);
list.RootFolder.Update();
taxonomyField
is the TermSet
Tema I would like to display.
After the code runs, the "Selected Hierarchy Fields" are Tema and Folders. If I remove Folders manually in the GUI, everything workes like it's supposed to.
I've tried to use mdnSettings.ClearConfiguredHierarchies();
first, to remove Folders. This sets up the correct fields in "Library Settings --> Metadata Navigation Settings", but does not display the Metadata navigation when viewing the document library. If I click "Ok" on "Metadata Navigation Settings", Folders is added automatically, and both Tema and Folders is displayed in the document library. And again, if i remove Folders, then click "Ok" everything works as I want it to.
Visual representation of Folders, which i would like to remove programmatically.