ASP.NET MVC 返回文件
将文件写入Response
public ActionResult Zip()
{
string fname = Server.MapPath("~\\App_Data\\TestDB.zip"); FileStream fs=new FileStream(fname,FileMode.Open,FileAccess.Read,FileShare.ReadWrite); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.android.package-archive";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + "MyApp.apk"); Response.AppendHeader("Content-Length", "" + fs.Length); byte[] bts=new byte[fs.Length];
fs.Read(bts, 0,(int) fs.Length);
Response.BinaryWrite(bts);
return null;
}
Write File Bytes to Response
public ActionResult Zip()
{
string fname = Server.MapPath("~\\App_Data\\bb.zip"); FileStream fs = new FileStream(fname, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.android.package-archive";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + "MyAppb.apk"); Response.AppendHeader("Content-Length", "" + fs.Length); byte[] bts = new byte[fs.Length];
fs.Read(bts, 0, (int)fs.Length); Response.OutputStream.Write(bts,0,bts.Length);
return null;
}
ASP.NET MVC 返回文件的更多相关文章
- Asp.Net Mvc 返回类型总结
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- Asp.net mvc 大文件上传 断点续传
Asp.net mvc 大文件上传 断点续传 进度条 概述 项目中需要一个上传200M-500M的文件大小的功能,需要断点续传.上传性能稳定.突破asp.net上传限制.一开始看到51CTO上的这 ...
- MVC图片上传、浏览、删除 ASP.NET MVC之文件上传【一】(八) ASP.NET MVC 图片上传到服务器
MVC图片上传.浏览.删除 1.存储配置信息 在web.config中,添加配置信息节点 <appSettings> <add key="UploadPath" ...
- Asp.net MVC 处理文件的上传下载
如果你仅仅只有Asp.net Web Forms背景转而学习Asp.net MVC的,我想你的第一个经历或许是那些曾经让你的编程变得愉悦无比的服务端控件都驾鹤西去了.FileUpload就是其中一个, ...
- 利用Asp.net MVC处理文件的上传下载
如果你仅仅只有Asp.net Web Forms背景转而学习Asp.net MVC的,我想你的第一个经历或许是那些曾经让你的编程变得愉悦无比的服务端控件都驾鹤西去了.FileUpload就是其中一个, ...
- Asp.net mvc 下载文件
前言 最近有需求需要下载文件,可能是image的图片,也可能是pdf报告,也可能是微软的word或者excel文件. 这里就整理了asp.net mvc 和asp.net webapi 下载的方法 A ...
- Asp.net mvc返回Xml结果,扩展Controller实现XmlResult以返回XML格式数据
我们都知道Asp.net MVC自带的Action可以有多种类型,比如ActionResult,ContentResult,JsonResult……,但是很遗憾没有支持直接返回XML的XmlResul ...
- asp.net mvc 多级文件夹
ASP.NET MVC - 定制属于你自己的ViewEngine 标签: asp.netmvcstring引擎razorapplication 2012-07-26 14:17 5365人阅读 评论( ...
- 解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题
问题背景: 在使用asp.net mvc 结合jquery esayui做一个系统,但是在使用使用this.json方法直接返回一个json对象,在列表中显示时发现datetime类型的数据在转为字符 ...
- MVC返回文件
上一篇 介绍了Action 返回View, 顺便也看到了返回Json的处理, 这一篇并不看文件返回的源码, 此篇是为了应用. 1. Response返回文件 在MVC的项目中, 还是能看到很多同事, ...
随机推荐
- element-ui的collapse中嵌套table表格 的 高度跳跃 问题
<script src="//unpkg.com/vue@2.6.10/dist/vue.js"></script><script src=" ...
- vue 2 中防抖节流在当前页面里写
isfilter(val) { // 过滤 this.debounce(() => { this.init(val); }, 1000); ...
- maven打包springboot项目不能运行的解决办法
前提是在开发工具中能正常运行,maven打包后无法运行. 打包后,进入打包文件路径 在dos下输出 java -version 显示jdk版本后,再 java -jar xxxx.jar xxx ...
- vue实现随机生成图形验证码
效果展示 安装插件 npm i identify 定义组件 verificationCode.vue <template> <!-- 图形验证码 --> <div cla ...
- vue指令入门
1. vue属性.事件.内容绑定 1 <div id="dv"> 2 <!-- v-cloak能够解决表达式闪烁问题 3 (当网速较慢时,会先出现{{msg}} ...
- shell脚本自动过滤尝试多次连接ip并添加到系统黑名单
#!/bin/bash cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c | awk '{{ print $2 " ...
- 【Linux】Linux网络编程
socket 默认开启的socket是阻塞的,想要设置非阻塞的话,可以用 fcntl设置为 nonblock:或者使用setsockopt进行更多设置: 一般使用推荐 设成nonblock,然后epo ...
- 容器之 docker的监控平台(prometheus + Grafana)
cAdvisor (Container Advisor) :用于收集正在运行的容器资源使用和性能信息.https://github.com/google/cadvisor Prometheus(普罗米 ...
- GPS北斗卫星时钟同步系统提升电信支撑网性能
GPS北斗卫星时钟同步系统提升电信支撑网性能 京准科技提供参考--更多资料VX(ahjzsz) 各项新的数据业务,如电子商务.多媒体通信.IP电话等都是电信业务发展的新增长点,而传统业务也存在多家企业 ...
- .net core layui折叠表格的应用。
效果展示 头部的折叠,展开,搜索按钮 <div class="layui-fluid"> <div style="margin-top: 20px;&q ...