第三方Girdview中文件下载的方法,以及js显示图片
2014-09-20 18:09
603 查看
/// <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();
}
}
相关文章推荐
- Asp.net中图片存储数据库以及页面读取显示通用方法详解-附源码下载
- MVC 保存二进制到数据库,并显示文件的方法(图片显示或下载文件)
- C# dbf文件在dataGirdView控件中显示方法
- 使用Form验证,未登录时登录页面无法显示图片、css、js文件的解决方法
- Asp.net 中图片存储数据库以及页面读取显示通用方法详解-附源码下载
- C# FileUpload上传视频、图片、文档,分别保存在不同的文件夹中以及下载文件的方法
- strusts2文件上传下载,以及二进制图片显示问题
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- android中webView JS调用Android的方法、webView的下拉刷新(SwipeRefreshLayout)、下载文件
- Asp.net中图片存储数据库以及页面读取显示通用方法详解-附源码下载
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- 下载远程(第三方服务器)文件、图片,保存到本地(服务器)的方法、保存抓取远程文件、图片
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- 在数据库中 存储图片 以及 在界面中显示图片(存储图片路径)- 这种方法相对与存储二进制文件好
- 利用discuz自带通行证整合dedecms的方法以及文件下载
- 用C语言写的ISAPI上传文件(图片)、显示图片、图片存储以及可供其它语言调用的方式、和程序源代码
- 各大门户网站Flash和JS实现的图片幻灯片切换特效代码文件下载:
- 用JS读取.txt文件方法以及一个操作.txt文件通用类方法【深海原创】
- 【Vegas原创】访问owa,图片和js脚本不能正常显示和使用的解决方法