zoukankan      html  css  js  c++  java
  • 将文件以流的形式另存为下载

    //【1】附件为本地磁盘路径(附件可以为图片、pdf、word等等)
    string
    strFile = Server.MapPath("/images/526763.pdf"); using (FileStream fs = new FileStream(strFile, 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("base.pdf", System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); }

    //【2】附件为网络路径
    (附件可以为图片、pdf、word等等)
    WebClient wc = new WebClient();
    wc.Credentials = CredentialCache.DefaultCredentials;
    byte[] btPageData = wc.DownloadData("http://www.baidu.com/img/bd_logo1.png"); //获取网络附件流
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("base.png", System.Text.Encoding.UTF8));
    Response.BinaryWrite(btPageData);
    Response.Flush();
    Response.End();
    string strTargetHtml = Encoding.Default.GetString(btPageData);
    wc.Dispose();
     
  • 相关阅读:
    Linux下视频采集及其显示
    编译webcam_server
    mjpgstreamer
    linux下ffmpeg的安装
    armlinuxgcc的命令参数介绍
    ADS1.2如何生成BIN文件
    OpenJTAG下载bootloader 备忘
    Android 3.0 以下 使用Fragment 实例
    Dialog 学习备忘
    CentOS安装wsgi
  • 原文地址:https://www.cnblogs.com/zhangwj/p/9945578.html
Copyright © 2011-2022 走看看