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

原文地址:https://www.cnblogs.com/lanofsky/p/13672425.html