当前位置: 代码迷 >> ASP.NET >> .net 删除服务器图片,这个要如何解决,麻烦高手帮小弟我看看,非常感谢
  详细解决方案

.net 删除服务器图片,这个要如何解决,麻烦高手帮小弟我看看,非常感谢

热度:8545   发布时间:2013-02-25 00:00:00.0
.net 删除服务器图片,这个要怎么解决,麻烦高手帮我看看,非常感谢
The process cannot access the file 'D:\www.xxx.com\UploadFile\zp\1_Image_20120607112619.jpg' because it is being used by another process. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.IOException: The process cannot access the file 'D:\www.xxx.com\UploadFile\zp\1_Image_20120607112619.jpg' because it is being used by another process.

Source Error: 


Line 46: {
Line 47: Response.Write("已经存在");
Line 48: System.IO.File.Delete(Server.MapPath(filename));
Line 49: }
Line 50: else
 
==================================================================================
if (fuPhoto.PostedFile != null && fuPhoto.PostedFile.ContentLength > 0)
  {
  //ClassSave cs = new ClassSave();
   
  string filename =Label1.Text.ToString();
   
  try
  {
  //cs.DeleteImage(Server.MapPath(filename));
  if (System.IO.File.Exists(Server.MapPath(filename)))//是否存在
  {
  Response.Write("已经存在");
  System.IO.File.Delete(Server.MapPath(filename)); }
  else
  {
  Response.Write("没有文件");
  }

  //System.IO.File.Delete(Server.MapPath(filename));
  //fuPhoto.PostedFile.SaveAs(Server.MapPath(filename));
  Image1.ImageUrl = filename;
  }
  catch (InvalidCastException tsg)
  {
  Response.Write("<script lanuage=javascript>alert('上传失败,原因" + tsg + "');location='javascript:history.go(-1)'</script>");
  Response.End();
  }


  }
  else
  {
  Response.Write("<script lanuage=javascript>alert('请选择上传文件');location='javascript:history.go(-1)'</script>");
  Response.End();
  }

------解决方案--------------------------------------------------------
在操作图片的地方Dispose(),另外你试试重启下电脑,就能删除了。
  相关解决方案