title: Last Modified Property When Streaming a File to an External SharePoint
body: <p>I am currently working with a windows service that moves files from certain locations and keeps them in sync with SharePoint Document Libraries.</p>
  
  <p>The uploading/syncing/etc functionality behaves fine but I am having issues with file properties. When uploading (code sample below) the files LastModified property is set to the time the file was uploaded. This is not the case if I directly Copy/Paste the file to the directory.</p>
  
  <p>I have looked into the possibility of just changing the property once it has been uploaded but that is not ideal. From testing it seems this is caused by the stream being "built" as a new file on the other end? Is there a way to send file properties with the file?</p>
  
  <pre><code>public static string UploadFile(string destUrl, string sourcePath, CredentialCache cc)
  {
      try
      {
          Uri destUri = new Uri(destUrl);
          FileStream inStream = File.OpenRead(sourcePath);
          WebRequest req = WebRequest.Create(destUri);
          req.Method = "PUT";
          req.Headers.Add("Overwrite", "F");
          req.Timeout = System.Threading.Timeout.Infinite;
          req.Credentials = cc;
          Stream outStream = req.GetRequestStream();
          byte[] buffer = new byte[32768];
          int read;
          while ((read = inStream.Read(buffer, 0, buffer.Length)) &gt; 0)
          {
              outStream.Write(buffer, 0, read);
          }
          outStream.Flush();
          outStream.Close();
          inStream.Flush();
          inStream.Close();
          WebResponse ores = req.GetResponse();
          ores.Close();
          return "success";          
      } //End Try for Try/Catch of UploadFile()
      catch (Exception ex)
      {
          return ex.Message;
      } //End Try/Catch for UploadFile()
  } //End UploadFile()
  </code></pre>
  
  <p><strong>EDIT - Additional info</strong></p>
  
  <p>To sum up the comment I left on an answer below:</p>
  
  <p>I have also noticed since I posted the question that Sharepoint lists the information as new even if you directly copy it since it is based on the database info (I believe?). I have looked into <code>File.SetLastWriteTime</code> but it seems that SharePoint doesn't like me touching things.</p>
  
  <p>I have also tried setting the traits and uploading files using the SharePoint calls but since I am posting to an external SharePoint instance I am unable to authenciate unless I go the <code>WebRequest</code> route.</p>