I require to programatically create a new document using the Document Template URL of the document Library and this requires to be done using the Client Object Model. I also require to do this without using workflow.

Could someone advise on how this can be done?

1 Answer 1


You can try something like this:


  function createDocument()
    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var docLib = web.get_lists().getByTitle("Docs");

    var rootFolder = docLib.get_rootFolder();

    var files = rootFolder.get_files();

        files.addTemplateFile(rootFolder.get_serverRelativeUrl() + "/foo.docx", 0);

      function(sender, args){alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());}

<div><a href="javascript:void(0)" onclick="createDocument()">Create Document</a></div>
  • Hi @Matthias , I've just tried to implement your code, it creates the document but it is somehow damaged, It doesn't open. I am using a custom content type with custom document template. Do I have to specify any other properties in this case? any ideas? Thanks!
    – Gintas K
    Commented Apr 12, 2016 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.