简体   繁体   中英

I can't read from a file using iwebHostEnvironment but I can read it if I specify the file path explicitly

I can read a file if I specify the file path using the uncommented code but if I try to do the same thing using IWebHostEnvironment, I am not able to do it.

IWebHostEnvironment is the path to wwwroot.

The error is: System.IO.DirectoryNotFoundException: Could not find a part of the path

System.IO.DirectoryNotFoundException: Could not find a part of the path

To troubleshoot the issue, you can debug the code to check if the generated path is as expected.

Besides. you can try the following code snippet.

string locl = Path.Combine(this.iwebHostEnvironment, @"Templates\Manifest\defaultManifest.yml");

Test Result

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM