简体   繁体   中英

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?

尝试使用

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM