Reputation: 603
I have an Asp.Net Core 1.0.0 app that runs on both Linux and Windows. In the app I need to upload files and save them in wwwroot
subfolders. I get IHostingEnvironment.WebRootPath
and specify a subfolder. It works fine on Windows but not on Linux because of paths. Window's \
of course is not going to work. So how can I detect whether my app is running on Windows or Linux from controller and choose an appropriate path delimiter?
Upvotes: 1
Views: 1207
Reputation: 118947
Rather than this, you should use Path.Combine
to generate directory names. For example:
var root = env.WebRootPath;
var myDirectory = Path.Combine(root, "subdirectory");
Upvotes: 3