0

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

         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 资源管理器上运行。

4

1 回答 1

1

连接网络共享时如何提供用户名和密码-看答案

您不能使用 WebClient 将文件写入 UNC 路径

于 2012-04-26T10:52:20.220 回答