/// <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. 对ToString("X2 ")的理解

    /// <summary>        /// 将byte型转换为字符串        /// </summary>        /// <param name=&q ...

  2. git clone错误

    git clone错误 Initialized empty Git repository in ***/.git/ error: The requested URL returned error: 4 ...

  3. java基础知识--CLASSPATH

    如果在一个类中用到了另外一个类(new了一个新对象). package com.xxx.xxx; public class Cat { } //下面是另外的文件 public class Dog { ...

  4. android 帧动画的实现及图片过多时OOM解决方案(一)

    一,animation_list.xml中静态配置帧动画的顺序,如下: <?xml version="1.0" encoding="utf-8"?> ...

  5. url中

    url中汉字被转换为UTF-8,通过此网址可以解析UTF-8编码.在地址栏中输入文字或者其它的,则可能输入法或者是相关的程序进行解析. http://www.mytju.com/classcode/t ...

  6. HW职责 (Hardware Engineer)

    硬件设计就是根据产品经理的需求PRS(Product Requirement Specification),在COGS(Cost of Goods Sale)的要求下,利用目前业界成熟的芯片方案或者技 ...

  7. 理解python的with语句

    Python’s with statement provides a very convenient way of dealing with the situation where you have ...

  8. 搭建java web开发环境、使用eclipse编写第一个java web程序

    开发工具:eclipse-jee-juno-SR2-win32-x86_64(请自行官网下载) 使用服务器:apache-tomcat-7.0.35-windows-x64(请自行官网下载) 打开 e ...

  9. NPOI 单元格(cell) 格式参数

    NPOI 单元格(cell) 将格式设为文本 在网上找了很久,都没有关于如何设置的信息,没办法查了下NPOI的源码终于找到了方法.这里共享下,就是“@”参数 ICellStyle cellStyle ...

  10. UIKit框架之UITouch

    1.继承链:NSObject 2.获取触发点的位置 (1)- (CGPoint)locationInView:(UIView *)view :返回指定视图的触发点的位置 (2)- (CGPoint)p ...