您的位置:首页 > 其它

关于"未能映射路径"问题

2009-07-02 13:37 477 查看
未能映射路径,在作页面生成时,老是出现"未能映射路径"/aa/bb/cc".

研究了半天,终于找出原因了,Server.Mapth(string path),path-->是相对路径。所以,改为Server.Mapth("aa/bb/cc")就好了,.net 会自动找"aa/bb/cc",返回相对路径。

if (!System.IO.Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))
{
System.IO.Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(path));
}
System.IO.StreamWriter sw = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath(path + "/" + file), false, System.Text.Encoding.GetEncoding("gb2312"));
sw.Write(temp);

如果不存在,使用System.IO.Directory.CreateDirectory创建文件夹。

切记: Server.Mapth("相对路径").

解决方案一:将绝对路径/bin/WebSet.xml设为相对路径即可:~/aa/bb/WebSet.xml

解决方案二:使用System.Web.HttpContext.Current.Request.PhysicalApplicationPath+("/Bin/WebSet.xml");
其中System.Web.HttpContext.Current.Request.PhysicalApplicationPath表示的是项目的根目录。

解决方案三:aa/bb/WebSet.xml 。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐