删除上传时 同名图片文件

 

 

string mPhysicalName = HttpContext.Current.Server.MapPath(mPath + pImageNewName + '.' + mStrName[1]);
if (File.Exists(mPhysicalName))
      {
          this.deleteOldImage(mPhysicalName);
          fldBuyInfoImage.PostedFile.SaveAs(mPhysicalName);
 
          File.Copy(mPhysicalName, newFilePath, true);
          str = mPath + pImageNewName + '.' + mStrName[1];
      }
      else
      {
          fldBuyInfoImage.PostedFile.SaveAs(mPhysicalName);
 
          File.Copy(mPhysicalName, newFilePath, true);//小图:中文求购copy至海外求购
          str = mPath + pImageNewName + '.' + mStrName[1];
      }
 
    private bool deleteOldImage(string pImageUrl)
    {
        bool flag = false;
        try
        {
            if (pImageUrl != "")
            {
                FileInfo fi = new FileInfo(pImageUrl);
                if (fi.Exists)
                {
                    fi.Delete();
                    flag = true;
                }
            }
        }
        catch (Exception e) { }
        finally { }
        return flag;
    }

你可能感兴趣的:(文件)