开发者

Transferring files from one PC to another using C#?

I'm using C#. I want to get the files that are on the server PC to my PC. Both PCs are connected through network. I have given IP address of that PC in the path, but it's not copying the files to my folder. I'm using the following code, but it's not working:

File.Copy(Path.GetFileName(source开发者_运维百科File), Path.GetDirectoryName(targetpath));

In sourceFile I have given IP address + folder path of the server PC and in the targetpath i have given the path of the folder of my PC to which I want to copy the files.


Wy do you use Path.GetFileName? This function get only file name, not full path. The signature of File.Copy(string sourceFileName, string destFileName) means, that you must use full path to both files.

This code works good:

File.Copy(@"\\server\folder$\test.txt", "test.txt");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜