How to open a text file regarding my MVC project?

In my bin file, I installed som test data, and I want my application to have access to the log files that are stored in bin/log/log00001.txt .

However, in my crontroller, when I try to use TextReader in the following path, it goes somewhere else: new StreamReader("log/log00001.txt")

How to read material in relation to my project?

+6
source share
2 answers

Try using

 StreamReader reader = new StreamReader(Server.MapPath("~/bin/log/log00001.txt")); 
+10
source
 HttpContext.Current.Server.MapPath("~/some/path/relative/to/your/web/app") 
+4
source

Source: https://habr.com/ru/post/928024/


All Articles