title: How can I use Transaction in FILE OPERATIONS?
body: <p>My program needs to treat some file operations as a unit, some of the important steps in a case are:</p>
  
  <ol>
  <li>delete a file in a directory.  </li>
  <li>validate some data. if the data is invalid, <strong>roll back</strong>.</li>
  <li>Upload a file to the directory. if upload <em>failed</em> , <strong>roll back</strong>.</li>
  <li>commit changes.</li>
  </ol>
  
  <p>I raise this requirement about transaction is because sometimes a user may use VPN to access my website, the VPN connection maybe very unstable. </p>
  
  <p><strong>If the 3rd step faild, the 1st file and the new uploaded file will all LOST.</strong>  </p>
  
  <p>some of my code:</p>
  
  <pre><code>        DeleteTheOlderDT(path, FileName);
  
          this.fuTemplateName.SaveAs(path + FileName);
          _t.FileName = FileName;
  
          if (!System.IO.File.Exists(path + FileName))
          {
              ArrayList ItemList = new ArrayList();
              ItemList.Add("Uploading failed, please upload again!");
              btlError.DataSource = ItemList;
              btlError.DataBind();
              _t.FileName = "";
              return;
          }
  </code></pre>