Question

I have a document library in my SharePoint Online tenant with a custom content type with some fields and a specific document template thats puts the metadata into the document.

How should proceed to create a new instance of this content type? Do I have to create a new file first with at stream from the document template and then update the metadata or can I just treat it like a list item and create it and everything will be fine?

Was it helpful?

Solution

There is nothing in the SharePoint REST API which allows you to create a file using a template. You will have to create new file (empty) or with at least one page. Then set the metadata including the contentTypeId. The following link shows how to do this without creating more than one version if you have versioning on. You can adjust the code to include the contentTypeId.

http://sharepointfieldnotes.blogspot.com/2014/04/uploading-documents-and-setting.html

OTHER TIPS

I think there is a work around and here are the high level steps.

  1. create a document using UI and save it to the library and name it as "new_template_doc" or something like that

  2. if you don't want users to mess with this document, secure it so that no one will delete or update it.

  3. use the REST API "/copyto(strNewUrl, bOverWrite)" method to create (copy) a new document

/_api/Web/getfilebyserverrelativeurl('new_template_doc url')/copyto(strnewurl='destination_file_url', boverwrite=true)

Refer https://msdn.microsoft.com/en-us/library/office/dn450841.aspx for files and folders REST API

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top