IOException: The process cannot access the file 'file path' because it is being used by another process

前端 未结 10 2075
陌清茗
陌清茗 2020-11-22 00:13

I have some code and when it executes, it throws a IOException, saying that

The process cannot access the file \'filename\' because it

10条回答
  •  面向向阳花
    2020-11-22 00:39

    Using FileShare fixed my issue of opening file even if it is opened by another process.

    using (var stream = File.Open(path, FileMode.Open, FileAccess.Write, FileShare.ReadWrite))
    {
    }
    

提交回复
热议问题