当前位置:首页 > Windows程序 > 正文

C# 之 未能映射路径

2021-05-25 Windows程序

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

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

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

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

2. 未能找到路径“F:\DevelopFiles\weixinceshi\weixin\logs\log.txt”的一部分。

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

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

  解决方法:

string savePath = Server.MapPath(".\\logs\\"); if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70772.html