1

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?

3

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

  • hmm the metadata in the document does not get updated accoardingly to the metadata to the list item somehow. any ideas? – Pantani Feb 24 '15 at 7:55
1

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

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.