title: Create a copy of document in SharePoint 2010 document library using JavaScript
body: <p>I want to create a copy of document in the SharePoint document library.<br>
  Basically let us assume there is a template and every user will open the document by clicking on it. I want to create a copy of file user has clicked and open that file for editting.<br>
  I have tried using <a href="http://msdn.microsoft.com/en-us/library/hh185011.aspx" rel="nofollow">JavaScript Client Object model of SharePoint</a>. But the examples are for manipulating list items but not for document library.<br>
  Can any one please point to any sources that I can use to manipulate the files in document library  </p>
  
  <p>One restriction being I need to use JavaScript <em>object model</em> or <em>web services</em> to achive this functionality. i.e., <strong>NO</strong> server side code</p>
  
  <p>Following is the code I got till now</p>
  
  <ol>
  <li>The approach I am planning to use is copy the existing file object</li>
  <li>Rename it and</li>
  <li>Save it to other document library</li>
  </ol>
  
  <p>Please ignore formatting as I am not able to do it properly and this is under development code</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
   var clientContext = null;
          var web = null;
          var meetingItems = null;
          var filePath = null;
          var file = null;
          debugger;
          ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
  
  
          function Initialize() {
              clientContext = new SP.ClientContext.get_current();
              web = clientContext.get_web();
  
              this.list = web.get_lists().getByTitle("Documents");
  
              clientContext.load(list, 'Title', 'Id');
              var queryStart = "&lt;View&gt;"+ "&lt;Query&gt;"+ "&lt;Where&gt;"+ "&lt;Eq&gt;"+ "&lt;FieldRef Name='Title'/&gt;" + "&lt;Value Type='Text'&gt;"; 
                      var queryEnd = "&lt;/Value&gt;"+ "&lt;/Eq&gt;"+ "&lt;/Where&gt;"+ "&lt;/Query&gt;"+ "&lt;/View&gt;";
  
  camlQuery = new SP.CamlQuery(); 
  
  
  queryMeeting = queryStart + 'DevCookbook'+ queryEnd;
  
  camlQuery.set_viewXml(queryMeeting);
  
  meetingItems = list.getItems(camlQuery);
  clientContext.load(meetingItems);
  
              clientContext.executeQueryAsync(Function.createDelegate(this, this.onListLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
          }
  
          function onListLoadSuccess(sender, args) {
          filePath = meetingItems.get_item(0).get_path();
          file = meetingItems.get_item(0);
          debugger;
          clientContext.load(file);
  
              clientContext.executeQueryAsync(Function.createDelegate(this, this.onFileLoadSuccess), Function.createDelegate(this, this.onFileFailed));
  
             // alert("List title : " + this.list.get_title() + "; List ID : " + this.list.get_id());
  
             // doclist();        
          }
  function doclist()
  {
  var path = file.get_title();
  path = meetingItems.get_item(0).get_file().get_title();
  }
          function onQueryFailed(sender, args) {
              alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
          }
  
          function onFileLoadSuccess(sender, args) {
          debugger;
        alert("List title : " + this.list.get_title() + "; List ID : " + this.list.get_id());
  
  
          }
          function onFileFailed(sender, args) {
              alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
          }
  
  
          &lt;/script&gt;
  </code></pre>