Cannot create a file when that file already exists

前端 未结 4 1267
陌清茗
陌清茗 2021-02-14 17:14

I am using Winforms, and I am trying to copy a file from one location to another. If a file with the same name is already there, I want to overwrite it. But I get an error like

相关标签:
4条回答
  • 2021-02-14 17:22

    File.Copy(source,destination,true) will overwrite destination if permissions allow. See the docs.

    0 讨论(0)
  • 2021-02-14 17:33

    Check the write permission is allowed for the folder contains the destination file.

    Try the following:

    System.IO.File.Copy(src, dst, true);

    true if you want the existing file will be overwritten.

    To change or set file permission click here

    0 讨论(0)
  • 2021-02-14 17:36

    I had the same error. The destination should be the new filename, not the destination folder.

    0 讨论(0)
  • 2021-02-14 17:41

    have you tried File.Copy(src, dest, true). This might help overwriting the existing file.

    0 讨论(0)
提交回复
热议问题