我的代码是System.IO.File.Delete(this.Server.MapPath("..")+@"/VideoDemo/Video/"+fileName); 不知道这样是否是正确的?
还有判断文件存在的问题,为什么也是要用绝对路径,可以用相对路径解决吗??如
if(System.IO.File.Exists(this.Server.MapPath("..")+@"\VideoDemo\Video\"+fileName)==false)因为我怕别人访问时访问不了呀?

解决方案 »

  1.   

    都用绝对路径吧
    另外,建议用System.IO.Path.Combine来拼凑文件名
    这样可以减少\出现丢失或重复的问题
      

  2.   

    客户那里不是也要安装IIS的吗?只要将目录安装到input的wwwroot下,这样就跟我们开发这里的路径是一样的吗?
      

  3.   

    可以用相对路径。
    string picturePath = GetPicturePath(goods_id);
    if (File.Exists(this.Server.MapPath(picturePath)))
    {
       File.Delete(this.Server.MapPath(picturePath));
    }
    protected string GetPicturePath(int goods_id)
    {
       BLL.zqu_goods_goods bll = new zqu_goods_goods();
       DataSet ds = bll.GetList(" goods_id='" + goods_id + "'");
       string picPath = "~/uploadfile/" + ds.Tables[0].Rows[0][10].ToString();
       return picPath;
    }
      

  4.   

    物理觉得路径。
    例如:
    c:\www\1.txt
      

  5.   

    同意楼上的
    可以用相对路径。 
             string path = Server.MapPath("~/UploadImages/fwys/");
            string file = path + filename;
            if (File.Exists(file))
            {
                File.Delete(file);
                Common.Message(this,"附件删除成功!");
            }
      

  6.   

    汗,显然没有明白原理.操作时所有路径都是绝对的.
    Server.MapPath()就是获取绝对路径,你要把文件放在IIS有权限访问的目录下(一般在web目录下就可以,要删除的话就必须要有写权限).
    所以,你所谓的担心是多余也是没用的.你上面的拼接也是多此一举.