找不到网络路径

时间:2012-04-26 10:44:30

标签: c# .net webclient

我正在尝试将文件发送到我们的某个服务器,但我一直收到错误“找不到网络路径”。下面是我用来发送文件的代码

         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);
        }

请问我做错了什么。在测试时,服务器似乎可以在Windows资源管理器上运行。

1 个答案:

答案 0 :(得分:1)

How to provide user name and password when connecting to a network share - 看看答案

您无法使用WebClient将文件写入UNC路径