string strUrl = "http://www.sina.com.cn";
HttpWebRequest oRequest = (HttpWebRequest)WebRequest.Create(strUrl);HttpWebResponse oResponse  = (HttpWebResponse)oRequest.GetResponse();
StreamReader sr = new StreamReader(oResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("GB2312"));string sResultContents = sr.ReadToEnd();
oResponse.Close();
byte[]  bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(sResultContents);
FileStream fs = new FileStream("c:\\2.htm", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();

解决方案 »

  1.   

    string strUrl = "http://www.sina.com.cn";
    string filePath = "C:\\temp\\sina.htm"
    WebClient client = new WebClient();
    client.DownloadFile(strUrl,filePath);
      

  2.   

    下面的示例将文件从 http://www.contoso.com 下载到本地硬盘。 
    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" 
      

  3.   

    问题有点模糊,如果是web页面直接给个连接不就得了,或者加参数....
      

  4.   

    偶发现,MM给的分都很少~
    不知道这个MM^-^......
      

  5.   

    to:chinawn(chinawn) 你这家伙很细心啊,主要也是CSDN上的MM不多吧,只要是MM的问题大家都倾力相助,何必在乎分数多少呢,呵呵...
      

  6.   

    首先谢谢各位啦,我才申请的只有200分,所以也就没多少分给呀,客户端通过浏览器把web服务器上的任意指定文件下载到客户端的指定目录下,后来用的是FileInfo fi=new FileInfo(FileName.ToString ());
    Response.Clear();
    Response.ClearHeaders();
    Response.Buffer = false;
    Response.ContentType = "application/octet-stream";
    Response.AppendHeader("Content-Disposition","attachment;filename=" +HttpUtility.UrlEncode(fi.FullName,System.Text.Encoding.UTF8));
    Response.AppendHeader("Content-Length",fi.Length.ToString());
    Response.WriteFile(fi.FullName);
    Response.Flush();
    Response.End();