【发布时间】:2017-02-14 21:42:41
【问题描述】:
我正在尝试读取文本文件并将其显示在 plage 上。这就是我所做的。但我收到错误
进程无法访问文件 'D:\wwwroot\TestProject\Logs\TestLog.log' 因为它正被 另一个进程。
控制器代码
Array LogFileData = null;
var logFileNameWithPath = Server.MapPath("D:\wwwroot\TestProject\Logs\TestLog.log");
if (System.IO.File.Exists(logFileNameWithPath))
{
LogFileData = System.IO.File.ReadAllLines(logFileNameWithPath);
}
ViewBag.logFileContent = LogFileData;
查看代码
@if (ViewBag.logFileContent != null)
{
foreach (string dataLine in ViewBag.logFileContent)
{
@dataLine
<br />
}
}
日志文件由服务创建和使用。我的代码在我停止服务时有效。但我并没有试图在服务写入文件的同时专门写入文件。事实上,我正试图在服务没有写入它的时候阅读。关于如何解决这个问题的任何建议?谢谢。
【问题讨论】:
标签: asp.net asp.net-mvc-5 text-files temporary-asp.net-files