0

I'm trying to send a file to one of our servers but I keeping getting the error "network path not found". Below is the code I'm using to send the file

         try
        {                
            Console.WriteLine("Uploading file to server....Please wait!!");
            WebClient client = new WebClient();

            NetworkCredential nc = new NetworkCredential(userName, password, "domain");


            Uri address = new Uri(@"\\126.00.00.01\MyFolder\test.txt");

            client.Credentials = nc;

            string fullpath = Path.Combine(Directory.GetCurrentDirectory(), filePath);

            byte[] arrReturn = client.UploadFile(address, fullpath);
            Console.WriteLine("File uploaded sucessfully");
            System.Threading.Thread.Sleep(2000);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            System.Threading.Thread.Sleep(5000);
        }

Please what am I doing wrong. The server seems to work on windows explorer when test it.

Jay
  • 321
  • 3
  • 7
  • 19
  • 2
    StackOverflow is not a debugging service. – Jon Apr 26 '12 at 10:46
  • 1
    If you are trying to access your localhost with 126.00.00.01, perhaps try using the word localhost instead or 127.0.0.1, which are the correct references to your local machine. – ericosg Apr 26 '12 at 10:47
  • Should it not be 126.0.0.1 rather than 126.00.00.01? – Bali C Apr 26 '12 at 10:47
  • yea it is Bali but I still get the same error. And I'm doing this from a windows application – Jay Apr 26 '12 at 10:48
  • 1
    If it works fine for you via Windows explorer but not on another server, it must be either network access, or permissions surely? – Bridge Apr 26 '12 at 10:53
  • Yes you are right Bridge, my WebClient as actually disabled. It worked as soon as I enabled it. Thanks everyone for your interest. – Jay Apr 26 '12 at 11:02

1 Answers1

1

How to provide user name and password when connecting to a network share - Look at the answer

You cant use a WebClient to write a file to a UNC Path

Community
  • 1
  • 1
dunston
  • 2,670
  • 1
  • 21
  • 11