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\\..."
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.
If you write @"c:\\" it will refer your local drive on which the code is running so Please correct it
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.