简体   繁体   English

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

[英]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 : 查找共享文件夹的简单方法

  1. Open Run dialog. 打开Run对话框。
  2. Type computer name with preceding backslash eg \\\\ComputerNetworIdentity 输入带有反斜杠的计算机名称,例如\\\\ComputerNetworIdentity
  3. Locate the folders shared by the network computer. 找到网络计算机共享的文件夹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式获取另一台计算机上的共享文件夹的完整路径? - Programmatically get the full path of a shared folder on another computer? 将文件从服务器的共享文件夹复制到本地 - Copy file from shared folder of server to local 尝试将文件从我的计算机复制到同一网络上的另一台计算机 - Trying to copy a file from my computer to another computer on the same network 是否可以从Windows 10计算机中的共享文件夹中获取文件? - Is it possible to get a file from a shared folder in a windows 10 computer? 如何将文件从特定文件夹复制到C#中的共享文件夹? - How to copy file from a specific folder to a shared folder in C#? 如何从共享文件夹或另一台服务器复制和粘贴文件? - How to copy and paste the files from shared folder or from another server? 如何使用Windows服务将文件复制到共享文件夹(该共享文件夹在服务器上)? - How could i do to copy a file to a shared folder ( that shared folder is on server ) by using Windows service? 从文件夹中获取 xslx 和 xls 文件并将其复制到另一个文件夹中 - Get xslx and xls file from a folder and copy it in another folder 使用 web 服务将文件从一个服务器文件夹复制到另一个文件夹 - Copy a file from one server folder to another folder using webservice C#将最后一个文件从一个文件夹复制到另一个生成的文件夹 - C# copy last file from a folder into another generated folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM