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

后端 未结 2 1651
孤街浪徒
孤街浪徒 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.

提交回复
热议问题