URI如果是File URI和 HTTP URI,如何去执行具体的下载?谁能给个具体代码和在线资源,100分就是你的。

解决方案 »

  1.   

    public static void DownloadFile(string physicalFilePath)
    {
    FileStream stream=null;
    stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);    
    int bufSize = (int)stream.Length;
    byte[] buf = new byte[bufSize]; int bytesRead = stream.Read(buf, 0, bufSize);
    HttpContext.Current.Response.ContentType = "application/octet-stream"; 
    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
    HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
    HttpContext.Current.Response.End();
    }--------------
    DownloadFile(@"c:\aa.zip");
      

  2.   

    如果是File URI呢?上面的代码可行吗?
      

  3.   

    你要下载的文件是保存在服务器的站点所在的文件内还是在其他文件夹下?
    如果是站内文件夹你可以直接用超链接来下载文件
    <a href="http://网站/文件夹/要下载的文件名">
    如果是在其他文件夹下就可以参照“jc15271149(奶皮儿)”的方法,以文件流的方式来获取
      

  4.   

    我的是C/S结构的WinForm程序。在客户端会部署一个后台windows service执行下载,类似于windows操作系统的下载。把远程文件服务器上的文件通过file uri 或者http uri下载到客户端
      

  5.   

    System.net里面有方法直接下载文件的,走80端口