Programatically change the new menu in modern libraries

Brass Contributor

I am creating a lot of document libraries with code in our enterprise and each library should have different content types.

Unfortunately after updating the content types with CSOM, the default Word, Excel and PowerPoint templates disappear from the New-Menu in a modern library.

Instead the content types are shown.

 

Because I am not able to change the edit menu in hundreds of libraries back to the default, I would like to archive this within my software.

I already found how to do this with pnp powershell here, but would like to do it from withint C# (REST or CSOM)

 

Any ideas how I could archive that?

1 Reply

It was quite easy. Figured it out myself:

CSOM with C#:

 

var list = _sharePointCsomClient._clientContext.Web.Lists.GetByTitle(currentUnit.Name);
var defaultView = list.DefaultView;
_sharePointCsomClient._clientContext.Load(defaultView);
var menu = defaultView.NewDocumentTemplates = "[{\"templateId\":\"NewFolder\",\"title\":\"Folder\",\"visible\":true},{\"templateId\":\"NewDOC\",\"title\":\"Word document\",\"visible\":true},{\"templateId\":\"NewXSL\",\"title\":\"Excel workbook\",\"visible\":true},{\"templateId\":\"NewPPT\",\"title\":\"PowerPoint presentation\",\"visible\":true},{\"templateId\":\"NewONE\",\"title\":\"OneNote notebook\",\"visible\":true},{\"templateId\":\"NewXSLSurvey\",\"title\":\"Excel survey\",\"visible\":true},{\"templateId\":\"NewXSLForm\",\"title\":\"Forms for Excel\",\"visible\":true},{\"templateId\":\"NewVSDX\",\"title\":\"Visio drawing\",\"visible\":true},{\"templateId\":\"Link\",\"title\":\"Link\",\"visible\":true}]";
list.DefaultView.Update();
await _sharePointCsomClient.ExcecuteQueryAsync();