title: Deleting then recreating File older than x days c# keeping createdDate
body: <p>I am writing a script task in my SSIS package to delete the log file being used by the package if it is older than X number of days. Here is my current code:</p>
  
  <pre><code>if (File.Exists((String)Dts.Variables["ErrorLogLocation"].Value))
          {
  
              DateTime logCreatedDate = File.GetCreationTime((String)Dts.Variables["ErrorLogLocation"].Value);
  
              if (logCreatedDate &lt; DateTime.Now.AddDays(-3))
              {
                  try
                  {
                      File.Delete((String)Dts.Variables["ErrorLogLocation"].Value);
                  }
                  catch (Exception e)
                  {
                      using (StreamWriter sw = File.AppendText((String)Dts.Variables["ErrorLogLocation"].Value))
                      {
                          sw.WriteLine(DateTime.Now + " : "+ e);
                      }
                  }
  
                  using (StreamWriter sw = File.AppendText((String)Dts.Variables["ErrorLogLocation"].Value))
                  {
                      sw.WriteLine("New log Creation Date: " + File.GetCreationTime((String)Dts.Variables["ErrorLogLocation"].Value));
                  }
  
              }
          }
  </code></pre>
  
  <p>it seems like it would work, but the issue is when I delete the file, then write to a new file with the same name, the information inside is being wiped as expected, but the file creation date remains the same as before the deletion. This is an issue because i am basing when to delete this file on that datetime. The expected behavior in my mind is it would delete the file, then write to a completely new file with a new created date. </p>
  
  <p>Any idea what may be causing this? Is it due to the fact I am deleting a file then immediately appending to a file with the same name(which i would assume would just create a new file if it doesnt exist?) is this file still being kept in memory or something during that period?</p>