2

How would I use the SharePoint CSOM to configure the Metadata navigation Settings for the documents list? This is for an online SharePoint instance and I haven't been able to find anything online for this, is this even possible?

This video shows roughly what I am trying to achieve using the client side object model.

https://www.youtube.com/watch?v=aqt99a6fEXU

Thanks

2

I'd like to add relevant code to this question.

private static void AddMetadataNavigationToDocLib(ClientContext ctx, List docLib)
{
    var rootWeb = ctx.Site.RootWeb;

    ctx.Load(rootWeb, p => p.AvailableFields);
    ctx.Load(docLib, p => p.RootFolder, p => p.RootFolder.Properties);

    ctx.ExecuteQuery();
    if (rootWeb.AvailableFields.Any(p => p.InternalName.Equals(Common.Constants.TagsFieldName)))
    {
        var field = rootWeb.Fields.GetByInternalNameOrTitle(Common.Constants.TagsFieldName);

        ctx.Load(field, p => p.Id, p => p.InternalName, p => p.TypeAsString);
        ctx.ExecuteQuery();

        var sb = new StringBuilder();
        sb.Append("<MetadataNavigationSettings SchemaVersion='1' IsEnabled='True' AutoIndex='True'>");
        sb.Append("<NavigationHierarchies><FolderHierarchy HideFoldersNode='False' />");
        sb.AppendFormat("<MetadataField FieldID='{0}' FieldType='{1}' CachedName='{2}' CachedDisplayName='{3}' />", field.Id, field.TypeAsString, field.InternalName, field.InternalName);
        sb.Append("</NavigationHierarchies><KeyFilters /></MetadataNavigationSettings>");

        docLib.RootFolder.Properties["client_MOSS_MetadataNavigationSettings"] = sb.ToString();
        docLib.RootFolder.Update();
        docLib.Update();
        ctx.ExecuteQuery();
    }
}

From

https://srinivasananand.wordpress.com/2015/10/29/activating-document-lib-tree-navigation-using-csom/

PowerShell equivalent

function SetupDocumentTypeNavigation($webUrl, $listTitle)
{
    $context = GetContext $webUrl

    $web = $context.Web
    $list = $web.Lists.GetBytitle($listTitle)
    $listProps = $list.RootFolder.Properties
    $documentTypeField = $list.Fields.GetByInternalNameOrTitle("Document Type")

    $context.Load($web)
    $context.Load($list)
    $context.Load($listProps)
    $context.Load($documentTypeField)
    $context.ExecuteQuery()

    write-host ("Enabling Document Type Navigation..." + $nl)

    $sb = new-object System.Text.StringBuilder
    $sb.Append("<MetadataNavigationSettings SchemaVersion='1' IsEnabled='True' AutoIndex='True'>") | Out-Null
    $sb.Append("<NavigationHierarchies><FolderHierarchy HideFoldersNode='False' />") | Out-Null
    $sb.AppendFormat("<MetadataField FieldID='"+$documentTypeField.Id+"' FieldType='"+$documentTypeField.TypeAsString+"' CachedName='"+$documentTypeField.InternalName+"' CachedDisplayName='"+$documentTypeField.InternalName+"' />") | Out-Null
    $sb.Append("</NavigationHierarchies><KeyFilters /></MetadataNavigationSettings>") | Out-Null

    $list.RootFolder.Properties["client_MOSS_MetadataNavigationSettings"] = $sb.ToString()
    $list.RootFolder.Update()
    $list.Update()

    $context.ExecuteQuery()
}
  • This does exactly what I was trying to do, thanks! – Kevin.M Apr 19 '16 at 10:47
1

this is only available in (Microsoft.SharePoint.Client.DocumentManagement) API. however this is possible through PS: http://get-spscripts.com/2011/03/configuring-metadata-navigation.html

However you can try

Try the Microsoft.SharePoint.Client.Publishing.Navigation namespace: http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.publishing.navigation(v=office.15).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.