现在的位置: 首页 > 综合 > 正文

删除上传时 同名图片文件

2012年09月10日 ⁄ 综合 ⁄ 共 643字 ⁄ 字号 评论关闭

 

 

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;

    }

抱歉!评论已关闭.