Reputation: 21260
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.
Upvotes: 1
Views: 10303
Reputation: 13773
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");
Upvotes: 1
Reputation: 5430
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:
Run
dialog.\\ComputerNetworIdentity
Upvotes: 0
Reputation: 277
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
Upvotes: 0
Reputation: 17605
It seems that the target path _sharedLocation
also refers to a local path, not a remote path.
Upvotes: 0