有人請幫我解決這個錯誤。該進程無法訪問文件'E:\NewFolder\img.jpg'
,因爲它正在被另一個進程使用。該進程無法訪問文件'E: NewFolder img.jpg',因爲它正在被另一個進程使用
if (btn_Submit.Text == "Submit")
request.requestDetail.IMAGEPATH=Chosen_File==string.Empty ? Filepath +"NoImage.png" + ext : Filepath + txt_val.Text.ToUpper().Trim() + ext;
else
request.requestDetail.IMAGEPATH = Chosen_File == Filepath + "NoImage.png" ? (Filepath + "NoImage.png") : (Filepath + txt_val.Text.ToUpper().Trim() + ext);
ResponseDetail response = new ResponseDetail();
ABC_BL bl = new ABC_BL();
response = bl.InsertDetailBC(request);
if (response.result)
{
if (IsImageChanged)
{
if(!Directory.Exists(Filepath))
Directory.CreateDirectory(Filepath);
if(System.IO.File.Exists(Filepath+txt_val.Text.ToUpper().Trim() + ext))
System.IO.File.Delete(Filepath + txt_val.Text.ToUpper().Trim() + ext);
}
pb_Image.Image.Save(Filepath + txt_val.Text.ToUpper().Trim() + ext);
}
在執行此我得到錯誤System.IO.File.Delete();
的過程,因爲它正被另一個進程無法訪問該文件'E:\NewFolder\img.jpg'
。
上面的代碼看起來很好。但是這看起來像一個winforms應用程序,所以必須有一些GUI參與。如果您的用戶界面目前正在顯示您要刪除的圖像,則必須先刪除該圖像的圖像和引用,然後再刪除它 – cleftheris
是的,我做過。我仍然得到同樣的錯誤。 :( – Sowndarya
您是否可以更新您的問題以包含顯示圖像的UI代碼片段? – cleftheris