Issue
How to store file paths in a cross platform way in a .json
configuration file in ASP.NET Core?
E.g. I have the entry in the configuration:
MyPath: "C:\\Foo\\Bar"
And the path works on Windows, but does not work on Linux. I am aware of the Path.DirectorySeparatorChar
, but how could I use it in the .json
? Or should I use something different?
Solution
try it:
// 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);
}
Answered By - foad abdollahi Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.