将文件复制到共享文件夹的另一台计算机上 [英] copy a file to shared folder on another computer

查看:131
本文介绍了将文件复制到共享文件夹的另一台计算机上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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");

这篇关于将文件复制到共享文件夹的另一台计算机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆