日期:2014-05-18  浏览次数:20409 次

删除图片时报:正由另一进程使用,因此该进程无法访问
程序上传到服务器,删除图片,
报sys.webforms.pagerequestmanagerservererrorexception:文件“E:***”正由另一进程使用,因此该进程无法访问该文件

在本机运行删除是没有问题的,但上传服务器后出现这个问题。

部分代码如下:

  /// <summary>
  /// 删除相片按钮
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  protected void lbtnDele_Click(object sender, EventArgs e)
  {
  int photoId = Convert.ToInt32(ViewState["PID"]);
  MyPhotos photo = MyPhotosManager.GetMyPhotosByMyPhotosId(photoId);
  MyAlbum album = MyAlbumManager.GetMyAlbumByAlbumId(photo.AlbumId);
  if (album.HomePhotos == photoId) //如果要删除的相片为相册封面
  {
  album.HomePhotos = 0; //设置封面字段为0
  MyAlbumManager.UpdateAlbum(album);
  }
  else
  {
  DeleFile(photo.SavePath); //删除在硬盘上的图片  
  }
  List<PhotoComment> list = PhotoCommentManager.GetAllCommentByPhotoId(photoId);
  foreach (PhotoComment c in list)
  {
  List<ToReply> toList = ToReplyManager.GetAllReplyByCommentId(c.PhotoCommentId);
  foreach (ToReply t in toList)
  {
  ToReplyManager.DeleToReplyByToReplyId(t.ToReplyId); //删除所有回复
  }
  }
  PhotoCommentManager.DeleCommentByPhotoId(photoId); //删除图片的所有评论

  int i = MyPhotosManager.DelePhotoById(photoId); //从数据库中删除图片


  MyAlbum newAlbum = MyAlbumManager.GetMyAlbumByAlbumId(photo.AlbumId);
  int count = newAlbum.PictureNum;
  newAlbum.PictureNum = count - 1;
  int j = MyAlbumManager.UpdateAlbum(newAlbum); //更新相册照片数

  List<MyPhotos> alist = MyPhotosManager.GetAllByAlbumId(newAlbum.AlbumId);

  if (alist.Count > 0)
  {
  PhotoRreOrNext(0); //删除照片后,显示下一张照片
  }
  else
  {
  Response.Redirect("photo.aspx"); //如果这个相册只有一张照片,删除就跳入相册首页面
  }
  }

  /// <summary>
  /// 删除文件
  /// </summary>
  /// <param name="filePath"></param>
  public void DeleFile(string filePath)
  {
  try
  {
  string path = Server.MapPath(filePath);
  System.IO.FileInfo DeleFile = new System.IO.FileInfo(path);
  if (DeleFile.Exists)
  {  
  DeleFile.Delete();  
  }
  }
  catch (Exception ex)
  {
  throw ex;
  }
  }

   

 

------解决方案--------------------
探讨
引用:
我也认为是哪里资源没释放,再好好检查一下。主要是你封装的对象中

我找过好多次了。。。主要是在本地上。。。这代码是成功的。。
但发布到服务器上就出这问题了。。

------解决方案--------------------
探讨
我最开始跳入这个页面时,显示图片用了重绘之后缩放

是不是这个方式不好?

/// <summary>
    /// 加载时显示页面信息
    /// </summary>
    /// <param name="photoId"> </param>
    protected void Display(int photoId)