I have a document library with custom content type (template).
When I click the "new" button in the library it lets me to choose the template for new document or folder (default functionality).
Then I choose the template, it creates a new document using the template and opens it in Word Online for editing (I'm using SharePoint Online).
I am trying to somehow skip the opening of the new document.
Some time ago I had the same requirement on-prem and did this using C# code behind.
I've read lots of topics an tried lots of things, but didn't get it to work...
I have this bit of code at the moment, it creates the document on button click, but the document is somehow damaged, doesn't open at all...
var clientContext = new SP.ClientContext(siteUrl); var library = clientContext.get_web().get_lists().getByTitle('MyLibrary'); var rootFolder = library.get_rootFolder(); clientContext.load(library); var files = rootFolder.get_files(); clientContext.load(files); files.addTemplateFile("/sites/MySite/MyLibrary/MyDocument.docx", 0);
So it creates new "MyDocument.docx" file in "MyLibrary", but when I try to open it I get an error "The file is corrupt and cannot be opened"
I have checked the properties of the created document, everything looks fine...
Any ideas? Do I have to pass any other properties? Thanks!