开发者

Cannot create a file when that file already exists

开发者 https://www.devze.com 2022-12-11 02:24 出处:网络
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 开发者_Python百科already there, I want to overwrite it. But I get an error like \"Cann

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 开发者_Python百科already there, I want to overwrite it. But I get an error like "Cannot create a file when that file already exists."

I want to overwrite the file. What should I do? I tried File.copy instead of File.move, but I got the same error.


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


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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消