如何删除上传后不合要求的图片,有一个进程占用着刚才那图片!
string imgPosition = "upload/candidate ";
string savePath = " ", saveFile = " ";
savePath = Path.Combine(Request.PhysicalApplicationPath, imgPosition);
saveFile = Path.Combine(savePath, FileUpload1.FileName);
if (FileUpload1.HasFile)
{
try
{
FileUpload1.SaveAs(saveFile);
}
catch (Exception ex)
{
lb.Text = ex.Message;
lb.Visible = true;
return;
}
}
System.Drawing.Image img = System.Drawing.Image.FromFile(saveFile);
if (img.Width == 210 & img.Height == 280)
{
lb.Text = "上传成功! ";
lb.Visible = true;
Image1.ImageUrl = saveFile;
}
else
{
lb.Text = "图片规格为:210*280! ";
lb.Visible = true;
File.Delete(saveFile);****//问题在这,删不了!!!
}
------解决方案--------------------img.Close();
File.Delete(saveFile);