zoukankan      html  css  js  c++  java
  • 通过文件流stream下载文件

            public ActionResult ShowLocalizedXML(int id)
            {
                string orderName = "";
                string xmlString = GetXmlStream(id,out orderName);
                ViewBag.Xml = xmlString;
    
                XmlDocument doc = new XmlDocument();
                doc.CreateComment(xmlString);
    
                byte[] array = Encoding.UTF8.GetBytes(xmlString);
               //array = UnicodeEncoding.Convert(Encoding.UTF8, Encoding.Unicode, array);
                MemoryStream stream = new MemoryStream(array);  
    
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment; filename="+orderName+".xml");//Filename改成什么格式,就会下载什么格式文件
                Response.AppendHeader("Content-Length", "" + stream.Length);
    
                byte[] bts = new byte[stream.Length];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(bts, 0, (int)stream.Length);
    
                Response.OutputStream.Write(bts, 0, bts.Length);
                return View();
            }
  • 相关阅读:
    DebugView使用技巧
    网络抓包--Wireshark
    常用curl命令
    chrome.debugger
    修改php.ini 的timezone
    初识Elasticsearch,bulk 操作的遇到的那些事
    chrome 扩展 调试
    sqlite 时间戳转时间
    centos 升级sqlite3
    php 安装redis
  • 原文地址:https://www.cnblogs.com/shinima/p/4229012.html
Copyright © 2011-2022 走看看