开发者

Transferring files from one PC to another using C#?

开发者 https://www.devze.com 2022-12-23 19:07 出处:网络
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'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

精彩评论

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

关注公众号