就是用程序简单的把文件下载到本地

解决方案 »

  1.   


    C# 
    public void DownloadFile (
    string address,
    string fileName
    )
    参数
    address
    从中下载数据的 URI。 fileName
    要接收数据的本地文件的名称。 
      

  2.   

    using Syste.Net;
    WebClient.DownloadFile (String, String)
     将具有指定 URI 的资源下载到本地文件。  
      

  3.   

    下载也是分协议的,如果是http协议,可以用httpwebresponse,ftp协议的可以用ftpwebresponse。其他协议就得知道协议的格式然后用socket了。
      

  4.   

    下面是主要的代码部份
    先添加引用COM->Microsoft Xml, v3.0
    下面的StringFilePath参数是指存放目录,fn是指含文件后缀的完整文件名
    MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
    _xmlhttp.open("GET",Url,false,null,null);
    _xmlhttp.send("");
    if( _xmlhttp.readyState == 4 )
    {
    if(System.IO.File.Exists(HttpContext.Current.Server.MapPath(StringFilePath +"/"+  fn))) 
    System.IO.File.Delete(HttpContext.Current.Server.MapPath(StringFilePath +"/"+  fn));
    System.IO.FileStream fs = new System.IO.FileStream(HttpContext.Current.Server.MapPath(StringFilePath +"/"+ fn), System.IO.FileMode.CreateNew);
    System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
    try
    {
    w.Write((byte[])_xmlhttp.responseBody);
    w.Close();
    fs.Close();
    catch()