相关疑难解决方法(0)

如何使用.net StreamReader打开已打开的文件?

我有一些.csv文件,我正在使用它作为测试台的一部分.我可以打开它们并且没有任何问题地阅读它们,除非我已经在Excel中打开了文件,在这种情况下我获得了IOException:

System.IO.IOException:进程无法访问文件'TestData.csv',因为它正由另一个进程使用.

这是测试平台的片段:

using (CsvReader csv = new CsvReader(new StreamReader(new FileStream(fullFilePath, FileMode.Open, FileAccess.Read)), false))
{
    // Process the file
}
Run Code Online (Sandbox Code Playgroud)

这是StreamReader的限制吗?我可以在其他应用程序(例如Notepad ++)中打开该文件,因此它不能成为操作系统问题.也许我需要使用其他一些课程?如果有人知道如何绕过这个(除了关闭excel!)我会非常感激.

.net file readonly streamreader

48
推荐指数
3
解决办法
5万
查看次数

标签 统计

.net ×1

file ×1

readonly ×1

streamreader ×1