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();
            }
  • 相关阅读:
    字典
    列表
    重要的方法
    一笔"狗"销,"猪"事顺利!!!
    基础数据类型
    循环,格式化,运算符
    算法——三角形图形
    算法——字母金字塔
    算法——二进制求和
    Python power函数
  • 原文地址:https://www.cnblogs.com/shinima/p/4229012.html
Copyright © 2011-2022 走看看