try to set its Credentials property before downloadinghttp://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNetWebClientClassCredentialsTopic.asp?frame=truehttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemNetNetworkCredentialClassTopic.asp

解决方案 »

  1.   

    http://www.cndev.com.cn/kbview.asp?kbid=61832376
      

  2.   

    try
    {
    WebClient myWebClient = new WebClient();
    NetworkCredential myCredential=new NetworkCredential("administrator","lbj");
    //加身份验证
    myWebClient.Credentials=myCredential;
    string myStringWebResource = tbxSource.Text.Trim();
    string fileName=tbxXml.Text.Trim();
    myWebClient.DownloadFile(myStringWebResource,fileName);
    MessageBox.Show("下载完毕!");
    }
    catch(Exception myError)
    {
    MessageBox.Show("无法下载!"+myError.ToString());
    }
    这样写还是连不上
      

  3.   

    报错:
    ====================================================================================
    无法下载!System.Net.WebException: 在 WebClient 请求期间发生异常。 ---> System.UnauthorizedAccessException: 对路径“\\192.168.0.217\movie\omorrow.rmvb”的访问被拒绝。   at System.IO.__Error.WinIOError(Int32 errorCode, String str)   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)   at System.Net.WebClient.DownloadFile(String address, String fileName)   --- 内部异常堆栈跟踪的结尾 ---   at System.Net.WebClient.DownloadFile(String address, String fileName)   at transfor.Form1.btnDown_Click(Object sender, EventArgs e) in d:\key\transfor\form1.cs:line 553
      

  4.   

    is this account "administrator","lbj" network account? make sure it can access the file, or use a domain account instead