【发布时间】:2019-12-04 11:16:44
【问题描述】:
我有一个简单的问题,但它让我发疯了。
我有一个文件夹,里面有很多 JSON 文件,我只需要一个一个打开这些文件并做一些事情。
所以,我需要打开第一个,阅读并做一些事情,然后转到第二个等等,直到最后一个。
这是我试过的代码,在网上搜索:
string folderpath = @"C:\Users\rfo\Desktop\MM\VM DB\nv - master\nvd";
var fixedfolderpath = Environment.ExpandEnvironmentVariables(folderpath);
string [] filesnumber = Directory.GetFiles(fixedfolderpath, "*.json");
foreach (string filename in filesnumber)
{
var jsonFull = System.IO.File.ReadAllText(filename);
但我总是遇到错误DirectoryNotFoundException: Could not find a part of the path on the browser。
我正在使用 asp.net CORE 3 和 Visual Studio 2019。
【问题讨论】:
-
fixedfolderpath包含什么? -
AppPool 可能无权访问用户文件夹。并使用 Server.MapPath。
-
可能是访问权限问题。将文件夹移动到共享驱动器必须访问 asp.net 用户
-
请打印fixedfolderpath的输出,并在Directory.GetFiles之前执行if Directory.Exist(fixedfolderpath)
-
@JeroenvanLangen fixedfolderpath 包含大量 JSON 文件。
标签: c# json asp.net-core .net-core