我在本地生成Excel文件,当我想生成的文件名已存在时该怎么替换或删除与存在的文件!!
高手指点!在线等!!

解决方案 »

  1.   

    File.Copy("", "", true);替换以前有的文件
      

  2.   

    FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath(文件路径));
                        if (fi.Exists)
                        {
                            fi.MoveTo(HttpContext.Current.Server.MapPath(文件路径));
                        }
      

  3.   

    String path = "";// 旧文件路径
    FileInfo fi = new FileInfo(path);
                if (fi.Exists)
                {
                    fi.Delete(path);
                }
      

  4.   

    String path = "";// 旧文件路径 
    FileInfo fi = new FileInfo(path); 
    fi.Delete(path); 
    删除是不会报异常的