How do I read a local file in my ASP.NET Core project?

后端 未结 2 1652
孤街浪徒
孤街浪徒 2021-01-20 14:36

If I want to read a local file from my project, given a relative path from the project directory, how could I achieve this?

相关标签:
2条回答
  • 2021-01-20 14:55

    You can get the ApplicationBasePath from PlatformServices.ApplicationEnvironment. This will make it possible to resolve non-absolute paths relative to your application base path.

    0 讨论(0)
  • 2021-01-20 15:12

    Now that .NET Core has RTM-ed, you need to use IHostingEnvironment instead. It exposes WebRootPathand ContentRootPath.

    0 讨论(0)
提交回复
热议问题