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

前端 未结 10 2050
陌清茗
陌清茗 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:45

    I had this problem and it was solved by following the code below

    var _path=MyFile.FileName;
    using (var stream = new FileStream
        (_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
      { 
        // Your Code! ;
      }
    

提交回复
热议问题