Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create a file when that file already exists

Tags:

c#

.net

file-io

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 "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.

like image 435
Ramesh Avatar asked Nov 05 '09 08:11

Ramesh


People also ask

Can not create a file when that file already exists?

Several users are reportedly getting the “Cannot create a file when that file already exists” error when trying to change the status of the Smart Card (SCardSVR) service from Disabled to a different state. The issue is reported to occur with multiple Windows versions including Windows 7, Windows 8.1 and Windows 10.

How do I fix a file that already exists?

This error occurs at run time when the new file name, for example, one specified in a Name statement, is identical to a file name that already exists. Specify a new file name in the Name statement or delete the old file before specifying it in a Name statement.

Can not create a file when that file already exists IIS?

This error simply means something is already running on the port number that you are planning on using (and that probably means the default website is already using a binding with port 80, and you are attempting to add another website or application with a binding to port 80).

How do I delete a symbolic link in Windows?

To delete a symbolic link, treat it like any other directory or file. If you created a symbolic link using the command shown above, move to the root directory since it is "\Docs" and use the rmdir command. If you created a symbolic link (<SYMLINK>) of a file, to delete a symbolic link use the del command.


1 Answers

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

like image 65
Vinko Vrsalovic Avatar answered Sep 18 '22 06:09

Vinko Vrsalovic