locked
The process cannot access the file xxxx because it is being used in another process RRS feed

  • Question

  • User-1350042179 posted

    Hi

    I save a file with the code:

      private static void SaveFile(string fileName, byte[] data)
            {
                var directorio = ConfigurationManager.AppSettings["File:SharedPath"];
                if (data == null) throw new ArgumentNullException("data");
    
                var fileNamePath = string.Format(@"{0}\{1}", directorio, fileName);
    
                if (File.Exists(fileNamePath))
                {
                    File.Delete(fileNamePath);
                }
    
                using (var fileStream = new FileStream(fileNamePath, FileMode.Append))
                {
                    using (var bw = new BinaryWriter(fileStream))
                    {
                        bw.Write(data);
                    }
                }
            }

    It works fine in IIS Express, but in IIS.. it fails with the error:

    The process cannot access the file xxxx because it is being used in another process

    I don't understand why it fails.

    Sunday, July 5, 2020 9:43 PM

Answers

All replies