ftp下载

来源:互联网 发布:丹尼爱特牌子好吗知乎 编辑:程序博客网 时间:2024/04/28 17:57

try
        {
            string fileName = "xxx.xls";//客户端保存的文件名
            string filePath = Server.MapPath("downloadfile/xxx.xls");//路径

             //以字符流的形式下载文件
            FileStream fs = new FileStream(filePath, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();

            Response.ContentType = "application/octet-stream";
            //通知浏览器下载文件而不是打开
            Response.AddHeader("Content-Disposition", "attachment; filename=" +

HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
        }
        catch (Exception ex)
        {
            throw new Exception("下载失败,请稍后再试!");
        }

原创粉丝点击