4thSpace 4thSpace - 4 months ago 7
C# Question

"Could not find a part of the path" for windows client

I have a WPF client app. I'm try to get access to

c:\programdata\
, which I can clearly see is available. When I use File.Copy() and
c:\programdata\
as the destination, I get this error:


Could not find a part of the path


Anyone know what is wrong?

Answer

The File.Copy documentation states that destFileName is:

The name of the destination file. This cannot be a directory or an existing file.

You say you are passing C:\\programdata\\. That is a directory. You have to provide the path and the file name.

For example:

File.Copy("C:\\programdata\\source.txt", "C:\\programdata\\dest.txt");