“The process cannot access the file because it is being used by another process” with Images

前端 未结 7 986
梦毁少年i
梦毁少年i 2020-12-04 02:02

I\'ve seen many issues like this that have been solved and the problem was mostly due to streams not being disposed of properly.

My issue is slightly different, here

相关标签:
7条回答
  • 2020-12-04 02:26

    The create method opens the file for writing and returns a FileStream object for you to work with. Just because you are not referencing it does not mean it does not need to be returned.

    foreach (Images item in ListOfImages)
                    {
                        newPath = Path.Combine(newPath, item.ImageName + item.ImageExtension);
                        FileStream f = File.Create(newPath);
    
                        f.Write(item.File, 0, item.File.Length);
                    }
    
    0 讨论(0)
提交回复
热议问题