【发布时间】:2017-02-08 23:16:52
【问题描述】:
我从我的 C# 应用程序中打开一个 CSV 文件以使用
FileShare.Read
标志。我只附加到文件中 - 我从不尝试随机访问。如果我在我的应用程序仍在运行时从 Excel 打开文件,Excel 会给我一个预期的“打开只读/通知”提示。如果我选择“通知”,有时我的应用程序会在尝试使用
向文件写入新行时失败0x21 error - "The process cannot access the file because another process has locked a portion of the file."
我认为允许其他进程读取文件是安全的,但显然不是。无论如何要共享文件以供读取,同时防止另一个应用程序锁定它(我假设 Excel 尝试复制导致锁定的文件)?我还假设锁定只会影响复制时的字节 - 那么为什么附加到文件会影响呢?
【问题讨论】:
标签: c# excel file locking share