It is used to handle the user request coming from the browser. It will check the request from the browser and identify the action method and return the respective view. A controller is inherited from “ControllerBase” class which is inside the “System. Web.
If the file should not be directly available via URL, you should put it in App_Data.
For reading it, just use:
var fileContents = System.IO.File.ReadAllText(Server.MapPath(@"~/App_Data/file.txt"));
Ok this way it works for me (VS2017)
Use HostingEnvironment.MapPath(@"~/App_Data/file.txt")
(thanks to Hong comment)
var fileContents =
System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/App_Data/file.txt"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With