/// <summary>

/// 文件下载事件

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void Grid_OnCopyInsertClick(object sender, EventArgs e)         {

LinkButton LBut = sender as LinkButton;

string sellContractScanId = LBut.CommandName;

string url = "";

string name = "";

foreach (DataRow dr in griViewTable.Rows)             {

if (dr["序号"].ToString().Equals(sellContractScanId))                 {

url = dr["路径"].ToString();

name = dr["文件名称"].ToString();

break;

}             }

if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(url)))             {

Response.Redirect("UserInfoScanDownload.aspx?FilePath=" + url + "&FileName=" + name);

}

else

{                 bp.Alert("文件不存在!");

}

BasePage bp = null;

protected void Page_Load(object sender, EventArgs e)         {

if (Request["FilePath"] == null)

return;

if (Request["FileName"] == null)

return;

string fileRpath = Request["FilePath"].ToString();

string fileName = Request["FileName"].ToString();

if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(fileRpath)))             {

Response.ClearHeaders();

Response.Clear();

Response.Expires = 0;

Response.Buffer = true;

Response.AddHeader("Accept-Language", "zh-tw");

string name = System.IO.Path.GetFileName(fileRpath);

System.IO.FileStream files = new FileStream(HttpContext.Current.Server.MapPath(fileRpath), FileMode.Open, FileAccess.Read, FileShare.Read);                 byte[] byteFile = null;

if (files.Length == 0)                 {

byteFile = new byte[1];

}

else

{

byteFile = new byte[files.Length];

}

files.Read(byteFile, 0, (int)byteFile.Length);

files.Close();

Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));                 Response.ContentType = "application/octet-stream;charset=gbk";

Response.BinaryWrite(byteFile);

Response.End();

}

}

第三方Girdview中文件下载的方法,以及js显示图片的更多相关文章

  1. ubuntu下使用PIL中的show函数,无法显示图片的问题

    问题描述:ubuntu14.04系统,python2.7(version),正在学习python中, from PIL import Image im = Image.open('1.jpg') im ...

  2. PHP中的__toString方法(实现JS里的链式操作)

    _toString方法是在打印对象时自动调用的魔术方法,如果不声明会报以下错 Catchable fatal error: Object of class String could not be co ...

  3. MVC发布后项目存在于根目录中的子目录中时的css与js、图片路径问题

    加载固定资源js与css <script src="@Url.Content("~/Scripts/js/jquery.min.js")" type=&q ...

  4. JS与OC交互,JS中调用OC方法(获取JSContext的方式)

    最近用到JS和OC原生方法调用的问题,查了许多资料都语焉不详,自己记录一下吧,如果有误欢迎联系我指出. JS中调用OC方法有三种方式: 1.通过获取JSContext的方式直接调用OC方法 2.通过继 ...

  5. iOS之在webView中引入本地html,image,js,css文件的方法 - sky//////////////////////////////////////ZZZZZZZZZZZZZZZ

    iOS之在webView中引入本地html,image,js,css文件的方法   2014-12-08 20:00:16CSDN-sky_2016-点击数:10292     项目需求 最近开发的项 ...

  6. js中的tostring()方法

    http://blog.sina.com.cn/s/blog_85c1dc100101bxgg.html js中的tostring()方法 (2013-11-12 11:07:43) 转载▼ 标签: ...

  7. 秒味课堂Angular js笔记------Angular js中的工具方法

    Angular js中的工具方法 angular.isArray angular.isDate angular.isDefined angular.isUndefined angular.isFunc ...

  8. js中继承的方法总结(apply,call,prototype)

    一,js中对象继承 js中有三种继承方式 1.js原型(prototype)实现继承 代码如下: <SPAN style="<SPAN style="FONT-SIZE ...

  9. JS中通过call方法实现继承

    原文:JS中通过call方法实现继承 讲解都写在注释里面了,有不对的地方请拍砖,谢谢! <html xmlns="http://www.w3.org/1999/xhtml"& ...

随机推荐

  1. codeforces problem 140E New Year Garland

    排列组合题 题意 用m种颜色的彩球装点n层的圣诞树.圣诞树的第i层恰由l[i]个彩球串成一行,且同一层内的相邻彩球颜色不同,同时相邻两层所使用彩球的颜色集合不同.求有多少种装点方案,答案对p取模. 只 ...

  2. Get the current user permission level on a list item with ecmascript 分类: Sharepoint 2015-07-14 14:13 7人阅读 评论(0) 收藏

    To Check current users permissions using Ecmascript\Javascript client object model SharePoint 2010. ...

  3. centos设置静态ip地址

    1.修改网卡配置 编辑:vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为 ...

  4. centos7网络设置

    1.设置虚拟机网络连接方式 2.启动改为从驱动启动 3.启动虚拟机,使用命令 ip addr 查看ip,发现网卡配置为 eno16777736 如果找不到网卡配置文件,请返回安装过程,查看是否正确选择 ...

  5. java实现服务端守护进程来监听客户端通过上传json文件写数据到hbase中

    1.项目介绍: 由于大数据部门涉及到其他部门将数据传到数据中心,大部分公司采用的方式是用json文件的方式传输,因此就需要编写服务端和客户端的小程序了.而我主要实现服务端的代码,也有相应的客户端的测试 ...

  6. linux(centos)下挂载nefs文件系统

    有时候,在将硬盘插到Linux系统上,挂载硬盘时一直提示:unknown filesystem type 'ntfs'.在尝试网上的方法也遇到了一些问题. 这是有的 linux 发行版并不默认支持挂载 ...

  7. 封装captcha类 -- 画图四

    <?php // 验证码类 class Captcha{ //属性 private $width; private $height; private $length; private $line ...

  8. 安装R语言扩展包diveRsity-1

    今天去了学院的运动会呢-扮熊本熊超开心-写完这篇我补上我的图么么哒 ××××××××××××文末高能预警!!!!!这个包的安装并不是本周的任务!!!!!我真是萌萌哒×××××××××××××× ××× ...

  9. (转) 浅析HTML5在移动应用开发中的使用

    (转)浅析HTML5在移动应用开发中的使用 (原)http://www.iteye.com/magazines/67   2012-03-07  来自 UECD.163.com  编辑 wangguo ...

  10. sphinx,coreseek安装

    sphinx是国外的一款搜索软件. coreseek是在sphinx的基础上,增加了中文分词功能,换句话说,就是支持了中文. Coreseek发布了3.2.14版本和4.1版本,其中的3.2.14版本 ...