Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I require to create a 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 advice on how this can be done.

share|improve this question

1 Answer 1

You can try something like this:

<script>

  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();
    clientContext.load(rootFolder);

    var files = rootFolder.get_files();
    clientContext.load(files);

    clientContext.executeQueryAsync(
      function()
      {
        files.addTemplateFile(rootFolder.get_serverRelativeUrl() + "/foo.docx", 0);
        clientContext.executeQueryAsync();
      }, 

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

<div><a href="javascript:void(0)" onclick="createDocument()">Create Document</a></div>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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