1

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.

Night Walker
  • 20,638
  • 52
  • 151
  • 228
  • Are you sure that you are not just catching an exception elsewhere? Does the target folder require authentication? – Codor Apr 22 '14 at 09:05
  • Have a look at [Copy file on a network shared drive](http://stackoverflow.com/questions/1432213/copy-file-on-a-network-shared-drive) might give you a clue – huMpty duMpty Apr 22 '14 at 09:06
  • Have a Look at http://stackoverflow.com/questions/15801748/copying-local-file-to-network-shared-drive-issues or http://stackoverflow.com/questions/1432213/copy-file-on-a-network-shared-drive – Ajit Kumar Apr 22 '14 at 09:18

4 Answers4

1

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?

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");
Flater
  • 12,908
  • 4
  • 39
  • 62
0

It seems that the target path _sharedLocation also refers to a local path, not a remote path.

Codor
  • 17,447
  • 9
  • 29
  • 56
0

I guess you sharedLocation path is not valid.

If you write @"c:\" it will refer your local drive on which the code is running so Please correct it

Harikant
  • 269
  • 1
  • 6
  • File.Copy should work whether that path points to a local or remote location. I think the issue comes from the face that the given filepath is a *folder shortcut*, not an actual *folder*. – Flater Apr 22 '14 at 09:22
0

Problem: Your shared Path refers to C: drive of same machine. 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. You must have Write permission on shared folder.

Simple Way Locate A Shared Folder:

  1. Open Run dialog.
  2. Type computer name with preceding backslash e.g. \\ComputerNetworIdentity
  3. Locate the folders shared by the network computer.
Hassan
  • 5,360
  • 2
  • 22
  • 35