【发布时间】:2019-11-15 17:24:47
【问题描述】:
当我尝试删除图像时出现此错误,我尝试处理图片框,但这似乎不起作用。
System.IO.IOException: '进程无法访问文件 'C:\Users*******\Documents\Visual Studio 2019\项目****************\dbo\DBImages\Bolgheri Sassicaia.jpg' 因为它正被另一个进程使用。'
我从这个文件夹加载的图像,我想删除它,然后添加另一张同名的图片。 我非常想更新图像。
这是我将图像加载到图片框的地方
if (imagepathtext.TextLength > 0)
{
image1 = Image.FromFile(imagepathtext.Text);
drinkImageView.Image = image1;
}
这是我尝试替换图像的地方。
private void UpdatebtnClick(object sender, EventArgs e)
{
if (imagepath.TextLength > 9)
{
DialogResult result = MessageBox.Show("Are you also trying to
update image?", "Confirmation", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
image1.Dispose();
System.IO.File.Delete(imagepathtext.Text);
}
}
}
【问题讨论】: