PictureBox Problem
-
the problem is here:
string currentPath; private void frmPicture_Load(object sender, System.EventArgs e) { currentPath = @"D:\Image\1.jpg"; this.pictureBox1.Image = Image.FromFile(currentPath); } private void updateButton_Click(object sender, System.EventArgs e) { if (File.Exists(currentPath)) { string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext; this.pictureBox1.Image = null; File.Copy(currentPath, newPath, true); } }
Error: the process cannot access the file "D:\.." because it is being used by another process. what can i do to correct this problem. thanks. Rock Throught The Night -
the problem is here:
string currentPath; private void frmPicture_Load(object sender, System.EventArgs e) { currentPath = @"D:\Image\1.jpg"; this.pictureBox1.Image = Image.FromFile(currentPath); } private void updateButton_Click(object sender, System.EventArgs e) { if (File.Exists(currentPath)) { string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext; this.pictureBox1.Image = null; File.Copy(currentPath, newPath, true); } }
Error: the process cannot access the file "D:\.." because it is being used by another process. what can i do to correct this problem. thanks. Rock Throught The Night -
I assume it's the
File.Copy
line that throws the error? Out of interest, you've not got the picture your copying open in another application have you? KPi known the error is File.Copy line but i cannot find out the to correct it. please help me again thanks Rock Throught The Night
-
the problem is here:
string currentPath; private void frmPicture_Load(object sender, System.EventArgs e) { currentPath = @"D:\Image\1.jpg"; this.pictureBox1.Image = Image.FromFile(currentPath); } private void updateButton_Click(object sender, System.EventArgs e) { if (File.Exists(currentPath)) { string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext; this.pictureBox1.Image = null; File.Copy(currentPath, newPath, true); } }
Error: the process cannot access the file "D:\.." because it is being used by another process. what can i do to correct this problem. thanks. Rock Throught The NightI have just tried the code with some adjustments for my file structure and it works fine. The only difference between my code and yours is the newpath string, i set mine to
@"c:\golfball2.bmp"
and when i clicked the update button i got a copy of golfball.bmp called golfball2.bmp. I assume the problem is that the destination for your file is currently being used by another application, or even by your application. Try hard coding thenewPath
string to@"c:\test.jpg"
. If that works then you will have to look at where your trying to write the copy to. Let me know how you get on. KP -
I have just tried the code with some adjustments for my file structure and it works fine. The only difference between my code and yours is the newpath string, i set mine to
@"c:\golfball2.bmp"
and when i clicked the update button i got a copy of golfball.bmp called golfball2.bmp. I assume the problem is that the destination for your file is currently being used by another application, or even by your application. Try hard coding thenewPath
string to@"c:\test.jpg"
. If that works then you will have to look at where your trying to write the copy to. Let me know how you get on. KPthe " currentPath " and the newPath is the same Folder and the " currentFileName " and "newFileName" is the same too so the error occur. Rock Throught The Night
-
the problem is here:
string currentPath; private void frmPicture_Load(object sender, System.EventArgs e) { currentPath = @"D:\Image\1.jpg"; this.pictureBox1.Image = Image.FromFile(currentPath); } private void updateButton_Click(object sender, System.EventArgs e) { if (File.Exists(currentPath)) { string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext; this.pictureBox1.Image = null; File.Copy(currentPath, newPath, true); } }
Error: the process cannot access the file "D:\.." because it is being used by another process. what can i do to correct this problem. thanks. Rock Throught The NightEither clone (via
Clone
- don't forget to cast it to anImage
) theImage
you get fromImage.FromFile
, or use aFileStream
and specifyFileShare.Read
at the very least, then read the image from the stream (theBitmap
class - a derivative ofImage
- accepts aStream
as a parameter).Microsoft MVP, Visual C# My Articles