File Download Tips for asp.net
use http header
protected void Page_Load(object sender, EventArgs e)
{
string format = Convert.ToString(ViewData["format"]);
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("费用报销表", Encoding.UTF8) + string.Format(".{0}",format));
//测试中发现:如果要想在IE中直接打开PDF,上行代码,不能有!!否则即使客户端有设置,也会使用 Adobe Reader/Acrobat 打开
Response.ContentType = string.Format("application/{0}",format);
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.BinaryWrite(ViewData.Model);
Response.Flush();
//prevent render html to client(critical)
Response.End();
request to doc directly
Response.Redirect(“http://localhost:2222/Docs/abc.doc”, true);
Tips:
至于客户端使用浏览器打开(当然必须要相应的浏览器插件支持),还是相应的application (MS-Word,Adobe Reader),打开前是否提示下载,Server端是无法控制的,这个和用户设置有关系。见图
相关文档:
示例
第一个示例演示如何创建 FileUpload 控件,该控件将文件保存到代码中指定的路径。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  ......
HiddenField 控件提供了一种在页面中存储信息但不显示信息的方法。例如,可以在 HiddenField 控件中存储用户首选项设置,以便可以在客户端脚本中读取此设置。若要将信息放入 HiddenField 控件中,请在两次回发之间将其 Value 属性设置为要存储的值。
一、功能
可以使用 HiddenFi ......
刚看到了一片文章 http://dotnet.csdn.net/page/a92a1213-9896-49c7-9c89-14ae5f0d87ae 提到如下几点:
1. 数据库连接超时
2. 创建的对象只管用,不管释放
3. 调试(Debug)模式下编译后,就用于应用环境中了
4. 实际作业模式分享
1,2,3比较好理解,我在做的时候犯了他说的 第三种错误,至 ......