mahesh
mahesh

Reputation: 3217

The given path's format is not supported error with File.copy() method

When i try to copy the file from local machine to other machine within the local network, through file.copy() method in c#, i am encountered with the error saying, The given path's format is not supported

I am using the following syntax

File.Copy(@"C:\temp\sample.txt", @"\\DEMO-PC\D:\DummyFolder\sample.txt", true);

Upvotes: 2

Views: 16208

Answers (1)

phoog
phoog

Reputation: 43056

Try replacing the colon with a dollar sign:

File.Copy(@"C:\temp\sample.txt", @"\\DEMO-PC\D$\DummyFolder\sample.txt", true);

EDIT

The ':' character has a special status in Windows paths; it's not legal to use it in the name of a file share. The '$' character also has a special status: it is used to designate hidden shares. Windows automatically creates hidden file shares for each drive on a computer; omitting the colon because it's not legal, and adding the '$' to hide the share.

See this knowledge base article for more information: http://support.microsoft.com/kb/314984

Upvotes: 9

Related Questions