I'm using visual studio 2013 to create a c# windows application and I'm facing this error.
When I'm trying to delete an image that I have been using in a picturebox this error message appears..:
System.IO.IOException: The process cannot access the file 'C:\Users\ALI PC\Documents\My Projects\Doctor Clinic\Doctor Clinic\Images\1.jpg' 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, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at Doctor_Clinic.Forms.ReportForm.deleteBtn_Click(Object sender, EventArgs e) in c:\Users\ALI PC\Documents\My Projects\Doctor Clinic\Doctor Clinic\Forms\ReportForm.cs:line 94
var file = @image;
using (var s = new System.IO.FileStream(file, System.IO.FileMode.Open))
{
PatientImage.Image = Image.FromStream(s);
}
PatientImage.Image = null;
PatientImage.Image.Dispose();
System.IO.File.Delete(file);