title: The process cannot access the file 'XXX' because it is being used by another process
body: <p>I get the following exception </p>
  
  <pre><code>Error Message:The process cannot access the file '....\folder\r.js' because it is being used by another process.    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
     at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
     at System.IO.StreamReader..ctor(String path, Encoding encoding)
     at System.IO.File.ReadAllLines(String path, Encoding encoding)
     at System.IO.File.ReadAllLines(String path)
     at PrepareEventDates()
  </code></pre>
  
  <hr>
  
  <p>My method :</p>
  
  <pre><code>protected HashSet&lt;string&gt; PrepareEventDates()
  {
      HashSet&lt;string&gt; str = new HashSet&lt;string&gt;();
      WebClient webclient = new WebClient();
      string path = System.Configuration.ConfigurationSettings.AppSettings.Get("sss").ToString();
      webclient.DownloadFile(path, Server.MapPath("r.js"));
      String[] JSLines = System.IO.File.ReadAllLines(Server.MapPath("folder/r.js"));
      String strDate = string.Empty;
      string toolTip = string.Empty;
      for (int i = 0; i &lt; JSLines.Length; i++)
      {
          string result = JSLines[i];
          int methodBodyStart = JSLines[i].IndexOf("DefineEvent(");
          if (methodBodyStart &gt;= 0)
          {
              methodBodyStart += "DefineEvent(".Length;
              int methodBodyEnd = JSLines[i].LastIndexOf(')');
              if (methodBodyEnd &gt;= 0)
              {
                  string methodBody = JSLines[i].Substring(methodBodyStart, methodBodyEnd - methodBodyStart);
                  var twoParams = methodBody.Split(',')
                     .Select(x =&gt; x.Trim(' ', '\'')).Take(2);
                  result = string.Join("|", twoParams.ToArray());
              }
          }
          str.Add(result);
      }
  
      return str;
  }
  </code></pre>