将文件复制到共享文件夹的另一台计算机上机上、另一台、共享文件夹、文件

2023-09-06 11:09:44 作者:无处告别

我想将文件复制到映射的网络位置。 如果我尝试做手工一切工作正常。

I am trying copy file to mapped network location. If I try to do it manually everything is working OK.

通过运行以下code我没有得到任何异常,但我没有得到code在需要的位置。

By running following code I don't get any exceptions but I not get the code at the needed location.

     string _sharedLocation = @"C:\Users\pddd\AppData\Roaming\Microsoft\Windows\Network Shortcuts\system-tests";

     if (Directory.Exists(_sharedLocation) && File.Exists(@"c:\\Automation\\Tests\\Test1\\events.json"))
     {
         File.Copy(@"c:\\Automation\\Tests\\Test1\\events.json", Path.Combine(_sharedLocation, "events11.json"), true);
     }

与该问题的任何建议。

Any suggestions with that issue.

推荐答案

在看 _SharedLocation 变量,它是在位置:... \的Windows \网络快捷键\ ...

looking at the _SharedLocation variable, it's on location: "...\Windows\Network Shortcuts\..."

我只是猜测这里,但你特林引用快捷方式到网络文件夹,而不是一个网络文件夹?

I'm just guessing here, but are you tring to refer to a shortcut to a network folder, rather than a network folder?

这不会有任何效果:

File.Copy(myOriginalFile, "C:\...\MyShortcutToANetworkFolder\myFile.txt");

为什么不呢?因为一个快捷方式基本上是一个的文件的,不是的文件夹的(它比这更复杂,但我保持简单的参数的缘故)。你不能把一个文件(或其他东西)变成快捷方式。您可以使用快捷键唯一要做的就是打开它。

Why not? Because a shortcut is basically a file, not a folder (it's more complicated than that, but I'm keeping it simple for argument's sake). You cannot put a file (or anything else) into a shortcut. The only thing you can do with a shortcut is open it.

您需要实际的网络文件夹路径。

You need the actual network folder path.

这将工作:

File.Copy(myOriginalFile, "\\myServer\myFolder1\myFolder2\myFile.txt");