C# 之 未能映射路径

  在开发中遇到此问题,如下原码,报错:未能映射路径:

 string filename = Server.MapPath("/logs/log.txt");

  解决方法,从根目录开始:

string filename = Server.MapPath("~/logs/log.txt");

2. 未能找到路径“F:DevelopFilesweixinceshiweixinlogslog.txt”的一部分。

  问题:如下代码不能创建路径;

if (!Directory.Exists(Server.MapPath(".//logs//")))
{
   Directory.CreateDirectory(Server.MapPath(".//logs//"));
}

  解决方法:

string savePath = Server.MapPath(".\logs\");
if (!Directory.Exists(savePath))
{
   Directory.CreateDirectory(savePath);
}
原文地址:https://www.cnblogs.com/xinaixia/p/4584180.html