/// <summary>
        /// 远程服务器下载文件
        /// </summary>
        /// <param name="URL">下载文件地址 如:http://www.baidu.com/img/baidu_jgylogo3.gif</param>
        /// <param name="Filename">下载后另存为(全路径)</param>
        private void DownloadFile(string URL, string filename)
        {
            Loads.Value = 0;
            try
            {
                System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
                System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
                System.IO.Stream st = myrp.GetResponseStream();
                System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
                byte[] by = new byte[1024];
                int osize = st.Read(by, 0, (int)by.Length);
                Loads.Maximum = osize;
                while (osize > 0)
                {                    so.Write(by, 0, osize);
                    osize = st.Read(by, 0, (int)by.Length);
                    Loads.Value = osize;
                }
                so.Close();
                st.Close();
                myrp.Close();
                Myrq.Abort();            }
            catch (System.Exception e)
            {
                MessageBox.Show("错误提示" + e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
//使用
DownloadFile("http://www.baidu.com/img/baidu_jgylogo3.gif", Application.StartupPath + "\\要下载的目录\\" + "baidu_jgylogo3.gif");  

解决方案 »

  1.   

    string remoteUri = "http://www.contoso.com/library/homepage/images/";
    string fileName = "ms-banner.gif", myStringWebResource = null;
    // Create a new WebClient instance.
    WebClient myWebClient = new WebClient();
    // Concatenate the domain with the Web resource filename.
    myStringWebResource = remoteUri + fileName;
    Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
    // Download the Web resource and save it into the current filesystem folder.
    myWebClient.DownloadFile(myStringWebResource,fileName);        
    Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
    Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);
    http://msdn.microsoft.com/zh-cn/library/ez801hhe(v=vs.80).aspx
      

  2.   

    下载:
     
    这里我们用<a>标签的形式实现下载;
     
    href://链接的是服务器上存放a.txt文件的路径;
     
    1 1 <a href='http://192.168.132.97:10082/item/a.txt'>a.txt</a> 
    通过左键点击,或者右键另存为即可下载;
     
    当然,这都只是最简单的;
      

  3.   


    <a href='1.rar'>下载</a>