怎么写代码实现这样的效果??
从Sql数据库中取出数据(存入为.doc文件);
现在点击按纽(详细)查看.doc 的内容. 弹出对话框(打开----保存----取消);
我想点打开时,直接看文件内容;
点保存时,直接另存为(弹出另存为对话框),但不要用(如迅雷这样的下载),直接可以保存就好了.
这是我写的代码:
protected void Page_Load(object sender, EventArgs e)
{ string strGkxID = Request.QueryString["GkxID"]; Database db = new Database();
try
{
SqlDataReader dataReader;
SqlParameter[] parameters = {
db.MakeInParam("@SYS_ACTION",SqlDbType.Char,3,"INF"),
db.MakeInParam("@GkxID",SqlDbType.Int,4,Convert.ToInt32( strGkxID )),
};
db.RunProc("sp_Sssb_Gkx_New", parameters, out dataReader);
if (dataReader.Read())
{
if (dataReader["fj"].GetType().ToString() == "System.DBNull")
{
Response.Write("没有附件可以显示!");
}
else
{
byte[] fj = (byte[])dataReader["fj"];
if (fj.Length == 0)
{
Response.Write("没有附件可以显示!");
}
else
{
Response.ContentType = "application/msword";
Response.BinaryWrite((byte[])dataReader["fj"]); //string fName = "";
//fName = HttpUtility.UrlEncode("果壳箱附件") + ".doc";
//Response.AddHeader("content-disposition", "attachment;filename=" + fName);
Response.Flush();
Response.End(); }
}
}
}
catch (Exception ex)
{
ErrLog.AddErrLog("2", "sp_Sssb_Gkx_New(Show -- Edit)", ex.Message);
Response.Write("<script language=javascript>alert('" + ex.ToString() + "');</script>");
}
finally
{
db.Close();
}
}
从Sql数据库中取出数据(存入为.doc文件);
现在点击按纽(详细)查看.doc 的内容. 弹出对话框(打开----保存----取消);
我想点打开时,直接看文件内容;
点保存时,直接另存为(弹出另存为对话框),但不要用(如迅雷这样的下载),直接可以保存就好了.
这是我写的代码:
protected void Page_Load(object sender, EventArgs e)
{ string strGkxID = Request.QueryString["GkxID"]; Database db = new Database();
try
{
SqlDataReader dataReader;
SqlParameter[] parameters = {
db.MakeInParam("@SYS_ACTION",SqlDbType.Char,3,"INF"),
db.MakeInParam("@GkxID",SqlDbType.Int,4,Convert.ToInt32( strGkxID )),
};
db.RunProc("sp_Sssb_Gkx_New", parameters, out dataReader);
if (dataReader.Read())
{
if (dataReader["fj"].GetType().ToString() == "System.DBNull")
{
Response.Write("没有附件可以显示!");
}
else
{
byte[] fj = (byte[])dataReader["fj"];
if (fj.Length == 0)
{
Response.Write("没有附件可以显示!");
}
else
{
Response.ContentType = "application/msword";
Response.BinaryWrite((byte[])dataReader["fj"]); //string fName = "";
//fName = HttpUtility.UrlEncode("果壳箱附件") + ".doc";
//Response.AddHeader("content-disposition", "attachment;filename=" + fName);
Response.Flush();
Response.End(); }
}
}
}
catch (Exception ex)
{
ErrLog.AddErrLog("2", "sp_Sssb_Gkx_New(Show -- Edit)", ex.Message);
Response.Write("<script language=javascript>alert('" + ex.ToString() + "');</script>");
}
finally
{
db.Close();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货