我想从文本文件中获取文本数据::
为此,我使用了像::
这样的代码 public ActionResult Log()
{
StreamReader reader = new StreamReader(Server.MapPath("~/Views/Builder/TestLogger.txt"));
return View(reader);
}
我从“Log4Net”制作了这个文本文件。 我想知道如何在 MVC 应用程序的“ View ”或“操作”中获取此文本文件的内容。
最佳答案
您可以使用此代码:
public ActionResult Log()
{
var fileContents = System.IO.File.ReadAllText(Server.MapPath("~/Views/Builder/TestLogger.txt"));
return Content(fileContents);
}
关于c# - 如何在我的 MVC 应用程序中打开文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18355653/