使用这个方法的时候怎么总是不起作用。在浏览器中输入http://192.168.1.120/File/setup.rar 会提示让你下载。为什么到了下面就不行了。System.Net.WebClient client = new System.Net.WebClient();
 client.DownloadFile(@"http://192.168.1.120/File/setup.rar",@"D:\Test");我想知道这是为什么,谢谢!

解决方案 »

  1.   

    本帖最后由 net_lover 于 2011-12-15 13:42:46 编辑
      

  2.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml;
    using System.Net;public partial class Default19 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            const string filePath = @"d:\a.txt";
            Uri rl = new Uri("http://localhost/GemsaTest/a.txt");
            try
            {
                using (WebClient wc = new WebClient())
                {
                    wc.DownloadFile(rl, filePath);                //string html = wc.DownloadString(url); 
                    //using (StreamWriter writer = new StreamWriter(filePath, false, wc.Encoding)) 
                    //{ 
                    //    writer.Write(html); 
                    //    writer.Flush(); 
                    //} 
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }     }    
    }