title: "Process cannot access the file because it is being used by another process"
body: <p>I need to upload a CSV file to an ASP.NET application, on an Azure server. Although it works fine on my local machine, when uploading it to the server the following error is thrown:</p>
  
  <blockquote>
    <p>"Process cannot access the file
    'C:\inetpub\wwwroot\ImportFiles\9_11.csv' because it is being used by
    another process"</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>        string fileName = DateTime.Now.ToString().Replace(':', '_').Replace('/', '_').Replace(' ', '_') + Convert.ToString((new Random()).Next(0, 999) * (new Random()).Next(0, 999));
          string path = Server.MapPath("ImportFiles") + "\\" + fileName + "" + FileImport.FileName.Substring(FileImport.FileName.IndexOf('.'));
          FileImport.SaveAs(path);
          string pathforSeconStream = path;
          try
          {
              Response.Write("&lt;script&gt; alert('In Try Block');&lt;/script&gt;");
              bool flag = true;
              int visiblemessageCount = 0;
              int rollNo = 1;
              StreamReader ColLine = new StreamReader(path);
              string ColInputline = ColLine.ReadLine();
              String[] ColsInput = ColInputline.Split(',');
              ColLine.Close();
              ColLine.Dispose();
              string preFix = "", RollNumber = "";
              StreamReader sr = new StreamReader(pathforSeconStream);
  }
  catch(Exception ex)
  {
  }   
  </code></pre>