如何以跨平台方式.json
在ASP.NET Core中的配置文件中存储文件路径?
例如,我在配置中有条目:
MyPath: "C:\\Foo\\Bar"
并且该路径在Windows上有效,但在Linux上无效。我知道Path.DirectorySeparatorChar
,但是如何在其中使用它.json
呢?还是我应该使用其他东西?
试试看:
// IWebHostEnvironment _webHost
// IConfiguration Configuration
var listOfPath = Configuration["my-path"].ToString()
.Split("\\", StringSplitOptions.RemoveEmptyEntries);
var uploadPath = Path.Combine(_webHost.WebRootPath );
foreach (var folders in listOfPath)
{
uploadPath = Path.Combine(uploadPath, folders);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句