title: How to remove a file moved with a FileUpLoad [asp.net] C#
body: <p>I have a process that loads, process and MOVES a file CSV. This behavior has been represented by 2 ways, but I have a problem in the 2nd one described below:</p>
  
  <ol>
  <li><p>The source and destination directories are set in a database. So read and move the file works excellent disappearing the copy from the source directory. (GOOD)</p></li>
  <li><p>The source directory has been got from a FileUpload control (fuControl.PostedFile.FileName) and destination is still set in a database. So read and move the file, but at this point, I see that the file is copied into destination directory but a locked copy remains in the source directory and only disappears if I refresh the page (F5) or quit the internet browser. (NOT GOOD) So, How can I avoid this?</p></li>
  </ol>
  
  <p>Here my sample code:</p>
  
  <pre><code>    private void RunProcess(string path)
      {
          try
          {
              using (StreamReader stream = File.OpenText(path))
              {
                  this.ProcessFile(stream);
              }
              string destination = this.GetDestinationPath(); //Get the path from DB
              string fileName = Path.GetFileName(path);
              File.Move(path, destination + fileName);
          }
          catch (Exception e)
          {
              throw new Exception(e.Message, e);
          }
      }
  </code></pre>
  
  <p><strong>-----EDIT-----</strong></p>
  
  <p>I have my FileUpload control in a repeater and I use it like this. It's not working, a copy is still remaining.</p>
  
  <pre><code>    protected void repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
      {
          if (e.CommandName == "Browse")
          {
              using (FileUpload fuSource = (FileUpload)e.Item.FindControl("fuSource"))
              {
                  if (fuSource != null)
                  {
                      if (String.IsNullOrEmpty(fuSource.FileName) == false)
                      {
                          string filePath = fuSource.PostedFile.FileName;
                          this.RunProcess(filePath);
                      }
                  }
              }
          }
     }
  </code></pre>
  
  <p><strong>-----EDIT 2-----</strong></p>
  
  <pre><code>    public void ProcessFile(StreamReader stream)
      {
          string line = String.Empty;
          while ((line = stream.ReadLine()) != null)
          {
              //Just 1 line.
              Console.WriteLine(line);
          }
      }
  </code></pre>