If I want to read a local file from my project, given a relative path from the project directory, how could I achieve this?
You can get the ApplicationBasePath
from PlatformServices.ApplicationEnvironment
. This will make it possible to resolve non-absolute paths relative to your application base path.
Now that .Net Core has RTM-ed you need to use IHostingEnvironment
instead. It exposes WebRootPath
and ContentRootPath
来源:https://stackoverflow.com/questions/35877583/how-do-i-read-a-local-file-in-my-asp-net-core-project