Muhammad Rehan Saeed
Muhammad Rehan Saeed

Reputation: 38447

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

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

Upvotes: 3

Views: 5208

Answers (2)

John Reilly
John Reilly

Reputation: 6269

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

Upvotes: 3

Pawel
Pawel

Reputation: 31610

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

Upvotes: 4

Related Questions