我生成静态页想生成在文件夹上一层的根目录下,然后写路径现在写string strFilePath = string.Format("~/{0}", strFileName);在本地测试的时候是好使的,在服务器上测试就不好使,会报错,而把~/去掉就好使了,但只生成在了本文件夹下我该用什么方法解决一下呢   拜托了 真的~~~~

解决方案 »

  1.   

    真很正常,因为发布后的根目录跟你本地调试是不一样的。或者你用../../的形式可以。。Web层只是项目下的一个文件夹。。你可以用本地IIS调试,而不用WebDev.或者你就判断下,再确定用哪个(目录是否存在)--
    仅供参考
      

  2.   

    ~是在ASP.NET中才能使用的路径表示符,表示ASP.NET应用程序(或网站的根路径)。
    ../../类似于这种表示是网站常用的相对路径表示符。
      

  3.   


    string strFilePath = string.Format("{0}{1}",'~/', strFileName);
    string strFilePath = string.Format("{0}{1}",'../', System.Web.HttpContext.Current.Server.MapPath(strFileName));
      

  4.   

    string strFilePath = string.Format("{0}", System.Web.HttpContext.Current.Server.MapPath(strFileName));
      

  5.   

    string strFilePath ="../"+  System.Web.HttpContext.Current.Server.MapPath(strFileName);