zoukankan      html  css  js  c++  java
  • 【C#】【Demo】 .net响应文件等等



    1、响应图片
                if (Request.Files == null || Request.Files.Count <= 0)
                {
                    return null;
                }
                var file=Request.Files[0];
                var stream = file.InputStream;
                byte[] bt =new byte[stream.Length];
                stream.Read(bt, 0, bt.Length);

                return File(bt, "image/jpeg");

    2、响应excel

         string path = AppDomain.CurrentDomain.BaseDirectory + "/template/excel";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path += "/data.xlsx";
            using (FileStream ms = new FileStream(path, FileMode.Create))
            {

        //工作簿对象写入流
                bookHelper.book.Write(ms);


                string titleName = "文件名";
                return File(path, "application/vnd.ms-excel", titleName + ".xlsx");
            }

  • 相关阅读:
    ruby学习总结03
    ruby学习总结02
    ruby学习总结01
    mongodb学习笔记
    mongodb数据库设计原则
    activiti学习总结
    Scala学习——隐式转换
    Scala学习——函数高级操作
    Scala学习——模式匹配
    Scala学习——集合
  • 原文地址:https://www.cnblogs.com/lanofsky/p/13672425.html
Copyright © 2011-2022 走看看