服务器文件后台处理方式:

a标签:

<a href="/FileUpload/DownloadFile?file=/UploadFiles/File/bfcd676b-13a8-4195-b85b-59d9b9ca35e3.doc" title="下载"><span class="fa fa-arrow-circle-down"></span></a>

后台:

        /// <summary>
/// 根据路径下载文件,主要用于生成的文件的下载
/// </summary>
/// <param name="file">文件路径</param>
/// <returns></returns>
public ActionResult DownloadFile(string file)
{
string realPath = Server.MapPath(file);
if (!FileUtil.IsExistFile(realPath))
{
return null;
}
string saveFileName = FileUtil.GetFileName(realPath); Response.WriteFile(realPath);
Response.Charset = "GB2312";
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel/msword";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(saveFileName));
Response.Flush();
Response.End(); return new FileStreamResult(Response.OutputStream, "application/ms-excel/msword");
}

二进制转文件处理方式(需要文件名和二进制数据):

a标签:

<a href="/DWGVersion/GetFilesByID?id=162" title="下载"><span class="glyphicon glyphicon-download"></span></a>

后台:

public ActionResult GetFilesByID(string id)
{
var dwgVersion = BLLFactory<DWGVersion>.Instance.GetDataById(id);
if (dwgVersion==null||dwgVersion.DrawingContent == null || dwgVersion.DrawingContent.Length == )
{
return null;
}
Response.Clear();
String strFileName = dwgVersion.FileName;//文件名称
Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName));
Response.Buffer = true;
Response.BinaryWrite(dwgVersion.DrawingContent);//二进制数据
Response.Flush();
Response.End(); return new FileStreamResult(Response.OutputStream, "application/ms-excel/msword");

最新文章

  1. Windows“神器”收集贴
  2. HTML: xhtml和html的區別
  3. linux下mongodb定时备份指定的集合
  4. ios英语口语800句应用源码
  5. JS判断是不是本页面并且,给标签添加属性和属性值
  6. 如何选择Javascript模板引擎(javascript template engine)?
  7. 对同一元素设置overflow-x:hidden,overflow-y:visible;属性值不生效
  8. HTTP的长短连接、长短轮询的区别(转载)
  9. 将TIBCO Host 实例注册为Windows服务
  10. 入Lucene的第一个坑
  11. Mac下配置Nginx负载均衡
  12. app个推(透传消息)
  13. 方便快捷的求导求积分解方程在线工具sage介绍
  14. pinpoint初始化hbase脚本报错
  15. HDU 1115(求质量均匀分布的多边形重心 物理)
  16. pip install时遇到MemoryError的原因和处理方法
  17. 循环内的switch中break和continue使用区别
  18. 完整的AJAX
  19. C++并发编程实战---阅读笔记
  20. 富文本存储型XSS的模糊测试之道

热门文章

  1. Python中排序的灵活使用
  2. POJ 3254 【状态压缩DP】
  3. MongoDB学习day05--MongDB开启权限验证,创建用户
  4. IntelliJ IDEA 基本配置入门
  5. OpenJudge百炼习题解答(C++)--题3142:球弹跳高度的计算
  6. 【Android开发-4】进入实践,最喜欢折腾的计算器
  7. Android使用am命令实现拨打电话、打开应用
  8. Java注释中的@deprecated与源代码中的@Deprecated
  9. Vue调试工具 vue-devtools
  10. 一个很小的C++写的MVC的例子