Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on desktop application on .net 4.5 Framework, WPF and c#. I have windows 8 machine. I am trying to upload my local file in network path, for this i am using file.copy() but when I am trying to executing it shows "The network name cannot be found." Exception.

Code is as follows:

C#
using (new Impersonator("username", "domain", "password"))
{
File.Copy(System.IO.Path.GetFullPath(strNetworkFileName),System.IO.Path.GetFullPath(networkPath), true);
 }


What I have tried:

I tried Impersonator interface but even that it's not working.
Posted
Updated 2-Mar-16 23:37pm
Comments
CHill60 2-Mar-16 7:10am    
When you debug this what is in strNetworkFileName and networkPath ... do those locations actually exist?
anurag9179 2-Mar-16 7:22am    
"strNetworkFileName" is local path of file and "networkPath" is destination path
e.g strNetworkFileName = @"\\local-machine-name\folder\filename.txt";
networkPath= @"\\destination-machine-name\folder\filename.txt";
CHill60 2-Mar-16 7:27am    
And do those locations actually exist? Does that username have access to them in that domain? Have you used the correct domain name?
peterkmx 2-Mar-16 7:44am    
Please logon on the remote machine and check if the folder there has a RW permissions for the domain user used in impersonation
peterkmx 2-Mar-16 7:49am    
and also, logon on the local machine with impersonation credentials and try browsing to the target folder on the remote machine. If this is not successful, than permissions needs to be added to the folder on the remote machine ...

1 solution

You're using UNC paths for both file specifications. A proper UNC path is "\\server\shareName\folder\file.ext".

The "localpath" should not be a UNC path as I doubt the first "folder" in your path is a valid Share. Workstations don't normally have Shares setup, except for the default administrative variety.

Your local path should be a fully qualified (starts with a drive letter) path to the local file.

The destination server MUST expose a Share that you can upload to. You can NOT just specify a machine name and a folder to put it in.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900