public class FileOpen : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
int DocumentId=System.Convert.ToInt32(Request.QueryString.Get("DocumentId"));
SqlDataReader DBContent = FetchContent(DocumentId); DBContent.Read();
string filename = (string)DBContent["FileName"];
filename = System.Web.HttpUtility.UrlEncode(filename,Encoding.UTF8);
Response.AddHeader("Content-Disposition","attachment;filename="+filename);
Response.ContentType = (string)DBContent["ContentType"];
Response.OutputStream.Write((byte[])DBContent["Content"], 0,System.Convert.ToInt32(DBContent["ContentSize"])); Response.Flush();
Response.End();
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
public SqlDataReader FetchContent(int DocumentId)
{
SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings.Get("ConnectionString2"));
SqlCommand Command = new SqlCommand("Select * From TIPS Where DocumentId=@DocumentId",Connection); SqlParameter Param1=new SqlParameter("@DocumentId", SqlDbType.Int);
Param1.Value = DocumentId;
Command.Parameters.Add(Param1);
Connection.Open(); return Command.ExecuteReader(CommandBehavior.CloseConnection);
}
{
private void Page_Load(object sender, System.EventArgs e)
{
int DocumentId=System.Convert.ToInt32(Request.QueryString.Get("DocumentId"));
SqlDataReader DBContent = FetchContent(DocumentId); DBContent.Read();
string filename = (string)DBContent["FileName"];
filename = System.Web.HttpUtility.UrlEncode(filename,Encoding.UTF8);
Response.AddHeader("Content-Disposition","attachment;filename="+filename);
Response.ContentType = (string)DBContent["ContentType"];
Response.OutputStream.Write((byte[])DBContent["Content"], 0,System.Convert.ToInt32(DBContent["ContentSize"])); Response.Flush();
Response.End();
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
public SqlDataReader FetchContent(int DocumentId)
{
SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings.Get("ConnectionString2"));
SqlCommand Command = new SqlCommand("Select * From TIPS Where DocumentId=@DocumentId",Connection); SqlParameter Param1=new SqlParameter("@DocumentId", SqlDbType.Int);
Param1.Value = DocumentId;
Command.Parameters.Add(Param1);
Connection.Open(); return Command.ExecuteReader(CommandBehavior.CloseConnection);
}
解决方案 »
- dropdownlist问题
- gridview中rowcommand获取值的问题?
- 关于iframe框架的问题
- 错误汇总控件的ShowMessageBox属性设置为True,但是在服务器不弹出提示框是怎么回事啊?
- 如何写Session的判断类!老是提示Session不存在引用??
- win2003+iis6.0上传大文件问题
- 如何把一个单一的值赋给DropDownList1呢?那位帮我一下。。。
- ACCESS中查询日期字段的问题
- X64 win7下程序移植问题
- “未将对象引用设置到对象的实例” 有没可能是服务自身的错误?
- 急死了:高手指点,就是在我datagrid中显示的数据,我想获取其中某个字段的内容,怎么做
- 求检查用户名的正则表达式
要源码的哦,谢了,呵呵
我也想要
存DOC等文件要读取流。很多例子。孟老大的网站那里也有。