Forum Discussion
Andy Jones
Mar 15, 2019Copper Contributor
Document Library "New" menu changes via code
Hi
Does anyone know if it's possible to change the New menu choices via code (CSOM or PnP Provisioning)? We have custom content types but would like to hide the names of these and instead have word, excel etc..
Thanks
Andy
For anyone else looking I managed to find it. In CSOM there's a property "NewDocumentTemplate" which takes a JSON structure.
view.NewDocumentTemplates = itemtoset;
view.Update();
await ctx.ExecuteQueryAsync();See https://petkir.wordpress.com/2018/10/26/change-new-menu-in-sharepoint-online-programmatically/
The same can be set via PNP Provisioning by setting NewDocumentTemplates as part of the default view definition.
Cheers
Andy
3 Replies
Sort By
- Andy JonesCopper Contributor
For anyone else looking I managed to find it. In CSOM there's a property "NewDocumentTemplate" which takes a JSON structure.
view.NewDocumentTemplates = itemtoset;
view.Update();
await ctx.ExecuteQueryAsync();See https://petkir.wordpress.com/2018/10/26/change-new-menu-in-sharepoint-online-programmatically/
The same can be set via PNP Provisioning by setting NewDocumentTemplates as part of the default view definition.
Cheers
Andy
Hi Andy Jones
if you need to hide / decide content type order inside new item action, you need to set this property
spList.RootFolder.UniqueContentTypeOrder
You can follow this approach
List contentTypeNameToHideOnNewButton = new List(); //add in list contentTypeNameToHideOnNewButton all ct you want to hide string ctDefault = "ct default name" //cut, client context, etc.. clientContext.Load(spList.RootFolder, x => x.ContentTypeOrder); clientContext.ExecuteQueryRetry(); IList ctoFolder = spList.RootFolder.ContentTypeOrder; foreach (var item in contentTypeNameToHideOnNewButton) { ContentType contentTypeToHide = spList.GetContentTypeByName(item); if (contentTypeToHide != null) { ContentTypeId idCT = contentTypeToHide.Id; int indexCT = ctoFolder.IndexOf(ctoFolder.Where(x => x.StringValue == idCT.StringValue).FirstOrDefault()); if (indexCT > -1) { ctoFolder.RemoveAt(indexCT); } } } spList.RootFolder.UniqueContentTypeOrder = ctoFolder; spList.RootFolder.Update(); spList.Update(); clientContext.Load(spList.RootFolder); clientContext.ExecuteQueryRetry();
Cheers, Federico- AnonymousNot with CSOM or PNP to my knowledge. But it might be achievable using an Application Customiser and some CSS to do it.