Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open a text file relative to my MVC project?

In my bin file I have set up som test data, and I want my application to be able to access logfiles that are stored in bin/log/log00001.txt.

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

How do I read stuff relative to my project?

like image 356
Jason94 Avatar asked Oct 18 '12 11:10

Jason94


2 Answers

Try using

StreamReader reader = new StreamReader(Server.MapPath("~/bin/log/log00001.txt"));
like image 164
chead23 Avatar answered Sep 19 '22 18:09

chead23


HttpContext.Current.Server.MapPath("~/some/path/relative/to/your/web/app")
like image 34
spender Avatar answered Sep 19 '22 18:09

spender