
it give me error the process cannot access the file it using by another process file
why this message show
and how to solve.the error show in line delete of file
my code as below
private void button11_Click_1(object sender, EventArgs e)
{
openFileDialog1.Title = "Insert an image ";
openFileDialog1.InitialDirectory = "c:";
openFileDialog1.FileName = "";
openFileDialog1.Filter = "JPEG Image|*.jpg|GIF Image|*.gif|PNG Image|*.png";
openFileDialog1.Multiselect = false;
if (openFileDialog1.ShowDialog() != DialogResult.OK)
return;
pictureBox2.ImageLocation = openFileDialog1.FileName;
}
private void button12_Click_4(object sender, EventArgs e)
{
const string new_dir = "\\\\192.168.1.5\\Personal Pictures";
MessageBox.Show(openFileDialog1.FileName);
string extension = System.IO.Path.GetExtension(openFileDialog1.FileName);
string renamed_name = textBox1.Text + "" + extension;
string fName = System.IO.Path.Combine(new_dir, renamed_name);
if (File.Exists(fName))
File.Delete(fName);this line give error
System.IO.File.Copy(openFileDialog1.FileName, fName);
string msg = string.Format("Copied {0} to {1}", openFileDialog1.FileName, fName);
MessageBox.Show(msg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if possible help me
thanks

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Nov 5, 2014, 1:58 AM EST
comment the line pictureBox2.ImageLocation = openFileDialog1.FileName, it will work.
Because the when you assign the file path to ImageLocation, the image is opened and used by the pictureBox2., so you cant delete the file.
ahmed saRank #8,218 · 226 reputationPosted Nov 5, 2014, 2:15 AM EST
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Nov 5, 2014, 2:31 AM EST
Please check it.
ahmed saRank #8,218 · 226 reputationPosted Nov 5, 2014, 2:56 AM EST
ahmed saRank #8,218 · 226 reputationPosted Nov 5, 2014, 10:34 AM EST
ahmed saRank #8,218 · 226 reputationPosted Nov 8, 2014, 8:11 AM EST