title: Sharepoint Item File replacement
body: <p>Hi I've been playing with a file that pertains to an Item in a Sharepoint list. This item is a document which i make changes to then convert to a PDF. I currently upload this PDF and replace the original document with it. Everything upto there seems to be working fine. However when i replace the file with the new one I cannot see the older versioning of this file when it was a document file. If this is not possible I have been given the flexability to duplicate the item before replacing the old file one with the new one. This way there is an original document file available and the new version.</p>
  
  <p>I currently have been playing with item.CopyTo() attempting to duplicate the item but have been unsuccessfull. Below is the code i am using to replace teh file (and the code i am working on to duplicate the item):</p>
  
  <pre><code>string newFileName = Path.GetFileNameWithoutExtension(file.Name) + ".old.docx";
  string url = item.Web.Url + "/" + Path.GetDirectoryName(item.Url) + "\\" + newFileName;
  item.CopyTo(url); //This is where my code crashes...
  
  using (BinaryReader binReader = new BinaryReader(File.Open(tempSavePath, FileMode.Open)))
  {
      byte[] fBin;
      string fileName = Path.GetFileNameWithoutExtension(file.Name) + ".pdf";
  
      file.CheckOut();
  
      fBin = binReader.ReadBytes((int)binReader.BaseStream.Length);
      item["Title"] = fileName;
      file.SaveBinary(fBin);
      file.MoveTo(Path.GetDirectoryName(item.Url) + "\\" + fileName, true);
      file.Item["Nombre"] = fileName;
      file.Update();
  
      file.CheckIn("");
  }
  </code></pre>
  
  <p>The error i get is: Cannot create an element in the specified destination. Please ensure the directory exists and you have the required permissions. <em>(The actual error im getting is in spanish so I translated it, might not be the exact message shown in english)</em></p>
  
  <p>Actual Message shown <em>(in spanish)</em>: No se puede crear un elemento en el destino solicitado. Compruebe que la carpeta existe y que tiene permiso para editarla.</p>
  
  <p>As far as Im conecerned permissions isnt an issue and the directory obviously exists since that is the current items directory... If there is any other way to go about this please feel free to post as this might not be the best solution... Thanks in advance!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It seems that the file is versioned as a document however the extension remains as PDF Any ideas how i can make the versioning keep the extension of the original file?</p>