[英]copy a file to shared folder on another computer
I am trying copy file to mapped network location. 我正在尝试将文件复制到映射的网络位置。 If I try to do it manually everything is working OK.
如果我尝试手动执行,则一切正常。
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. 关于该问题的任何建议。
looking at the _SharedLocation
variable, it's on location: "...\\Windows\\Network Shortcuts\\..."
查看
_SharedLocation
变量,它位于以下位置: "...\\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? 我只是在这里猜测,但是您是要引用网络文件夹的快捷方式 ,而不是网络文件夹吗?
This will never work: 这将永远无法工作:
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. 您需要实际的网络文件夹路径。
This will work: 这将起作用:
File.Copy(myOriginalFile, "\\myServer\myFolder1\myFolder2\myFile.txt");
看来目标路径_sharedLocation
也指的是本地路径,而不是远程路径。
I guess you sharedLocation path is not valid. 我猜您sharedLocation路径无效。
If you write @"c:\\" it will refer your local drive on which the code is running so Please correct it 如果您写@“ c:\\”,它将引用运行代码的本地驱动器,因此请更正
Problem : Your shared Path refers to C:
drive of same machine. 问题 :您的共享路径引用同一台计算机的
C:
驱动器。 Possibly you are referring to the shortcut of mapped network location. 可能是指映射网络位置的快捷方式。
string _sharedLocation = @"C:\Users\pddd\AppData\Roaming\Microsoft\Windows\Network Shortcuts\system-tests";
It should be: 它应该是:
string _sharedLocation = @"\\ComputerNetworkIdentity\SharedFolder\pddd\AppData\Roaming\Microsoft\Windows\Network Shortcuts\system-tests";
Shared computer can be located using \\\\ComputerName
. 共享计算机可以使用
\\\\ComputerName
。 You must have Write permission on shared folder
. 您必须对
shared folder
具有写权限。
Simple Way Locate A Shared Folder : 查找共享文件夹的简单方法 :
Run
dialog. Run
对话框。 \\\\ComputerNetworIdentity
\\\\ComputerNetworIdentity
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.