如何打开相对于我的MVC项目的文本文件?

时间:2022-09-11 16:30:47

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.

在我的bin文件中,我设置了som测试数据,我希望我的应用程序能够访问存储在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")

但是,在我的crontroller中,当我尝试在以下路径上使用TextReader时,它会转到其他地方:new StreamReader(“log / log00001.txt”)

How do I read stuff relative to my project?

我如何阅读与项目相关的内容?

2 个解决方案

#1


10  

Try using

StreamReader reader = new StreamReader(Server.MapPath("~/bin/log/log00001.txt"));

#2


5  

HttpContext.Current.Server.MapPath("~/some/path/relative/to/your/web/app")

#1


10  

Try using

StreamReader reader = new StreamReader(Server.MapPath("~/bin/log/log00001.txt"));

#2


5  

HttpContext.Current.Server.MapPath("~/some/path/relative/to/your/web/app")