【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");
        }

posted @ 2020-09-28 16:50  lanofsky  阅读(117)  评论(0编辑  收藏  举报