首页 > 解决方案 > System.IO.DirectoryNotFoundException 找不到路由的一部分

问题描述

我想.txt通过在项目文件夹中调用文件来读取和解析文件。这是读取的代码

string[] line = { };
string route = @"~\\file\\" + ".text";
line = System.IO.File.ReadAllLines(route);

当它尝试从文件中读取所有行时出现错误,它转到另一条路线,如下所示:

C:\Program Files (x86)\IIS Express\~\Files\.text

该项目位于D盘。

标签: c#asp.netasp.net-mvc

解决方案


string route = Server.MapPath(@"~\\file\\myfile.txt");
string[] line = System.IO.File.ReadAllLines(route);

推荐阅读