<a href="<%#Eval("path") %>" target="_blank">下载</a> 点击下载后是浏览器直接打开文件,怎么弄成下载文件
解决方案 »
- str = string.format("{\"bookname\":\"{0}\"}",strName);这样为什么不行?
- 控件小键盘的回车键,转换成tab键功能,怎么实现
- listview排序问题
- 一种数组随机排序算法(模拟洗牌),请问理论上是否可行?
- C# 如何判断process启动完毕
- 麻烦下大牛们,关于改变treeview节点然后保存数据库!! 困扰一天的问题了,已经没什么分了。。
- C#程序运行时内存不足
- txt文件中文本的提取,急!!!!!!!!!!!!!!!!!!!
- ref和out关键字
- 调用文件夹下的用户控件问题!!赶!!
- 报错:“child”不是此父级的子控件
- C# 3.0中对象构造器可以访问私有成员??
css这类的就直接打开了,但是一般的都是保存的
FileInfo Fi = new FileInfo(filePath);
if (Fi.Exists)
{
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(dt.Rows[0]["Name"].ToString(), System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(FileName), System.Text.Encoding.GetEncoding("utf-8")));
Response.ContentType = "application/octet-stream";
Response.WriteFile(Filepath);
Response.End();