传输文件从一台PC到另一个使用C#?一台、传输文件、PC

由网友(雾气萦绕)分享简介:我使用C#。我想要得到的是服务器的PC到我的电脑上的文件。两台计算机都通过网络连接。我已经给了PC路径的IP地址,但它不将文件复制到我的文件夹。我用下面的code,但它不工作:I'm using C#. I want to get the files that are on the server PC to my...

我使用C#。我想要得到的是服务器的PC到我的电脑上的文件。两台计算机都通过网络连接。 我已经给了PC路径的IP地址,但它不将文件复制到我的文件夹。我用下面的code,但它不工作:

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(sourceFile), Path.GetDirectoryName(targetpath));

的资源文件我已经给IP地址+服务器PC的文件夹路径,并在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的你用Path.GetFileName? 此功能只得到文件名,而不是完整路径。 File.Copy(字符串sourceFileName,串destFileName)的签名意味着,你必须使用完整路径,这两个文件。

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.

这code工作良好:

File.Copy(@"serverfolder$test.txt", "test.txt");
阅读全文

相关推荐

最新文章