The reprinted file is being used by another process and cannot be accessed by this process.
Address: http://www.cnblogs.com/enjoyprogram/p/4344799.html
Exception prompt: "The file is being used by another process and the process cannot access the file ". After opening a file, try to open the file again, or if you want to perform other operations on the file after opening the file, this error message may occur. This error is usually caused by a problem in parameter settings when System. IO. FileStream is constructed. Usually used directly: FileStream fs = new FileStream (fileName, FileMode. open) This method is used to Open a file in read-only sharing mode. However, if the file has been opened by a process with write permission, it cannot be read, therefore, FileStream fs = new FileStream (fileName, FileMode. open, FileAccess. read, FileShare. readWrite); set the file sharing mode to read/write: FileShare. readWrite. This will solve the problem.
If you want to delete or overwrite an image file after you load it to Picturebox, the above error message is displayed.
PictureBox1.Image = Image. FromFile (sFile); // This method is used to load the Image. After the page is closed, the file in this path may still be occupied by the thread and cannot be deleted or overwritten.
PictureBox1.ImageLocation = sFile;
FileStream fs = new FileStream (sFile, FileMode. Open, FileAccess. Read, FileShare. ReadWrite );
Byte [] bytes = new byte [fs. Length];
Fs. Read (bytes, 0, bytes. Length );
Fs. Close ();
MemoryStream MS = new MemoryStream (bytes );
Bitmap img = new Bitmap (MS );
PictureBox1.Image = img;
The file will no longer be occupied.