Error you might receive while doing File Operation, specially File.Move Operation.
Error:The process cannot access the file because it is being used by another process.

 Source: mscorlib

Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.__Error.WinIOError() at System.IO.File.Move(String sourceFileName, String destFileName)
Solution for Error The process cannot access the file because it is being used by another process.

This error might occurs whenever you are trying to upload file, without explicitly removing it from memory.
So ones you remove it from memory possibly this error will get resolved.

File Upload Method 1
protected void btnUploadImages_Click(object sender, EventArgs e)
  {
      //Get the File Name.
      string strPostedFileName = FileUploadImages.PostedFile.FileName;

      //Exit if No File Name was entered.
      //If file is Zero Length, it is empty or doesn't exist
      if (strPostedFileName != string.Empty && FileUploadImages.PostedFile.ContentLength != 0)
      {
          //Delete Old file before uploading new file.
          if (System.IO.File.Exists(strFilePath))
          {
              System.IO.File.Delete(strFilePath);
          }

          //Save-Upload File to server.
          FileUploadImages.PostedFile.SaveAs(strFilePath);

          //Release File from Memory after uploading
          FileUploadImages.FileContent.Dispose();
      }
  }
File Upload Method 2
If you are trying to do something like this
Image bmp = Bitmap.FromFile(“c:\Temp\Logo.bmp”);
bmp.Save(“c:\Temp\Logo.bmp”);
Than, replace that with following
Image bmp = Bitmap.FromFile(“c:\Temp\Logo.bmp”);
bmp.Save(“c:\Temp\Logo.bmp”);
bmp.Dispose();

File Upload Method 3
 
FileStream fs = new FileStream(FilePath, FileMode.Create, FileAccess.Write);
fs.Close();
fs.Dispose();
FileStream fs2 = new FileStream(FilePath, FileMode.Open);
fs2.Close();
fs2.Dispose();

 

ที่มา: http://dotnetguts.blogspot.com/2009/07/process-cannot-access-file-because-it.html
เพิ่มเติม: http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/e99a7cea-43d3-49b1-82bc-5669e0b9d052