protected void Page_Load(object sender, EventArgs e)
{
int id = int.Parse(Request.QueryString["id"].ToString());
SqlDataReader dr = null;
SqlConnection objCn = new SqlConnection();
objCn.ConnectionString = "Data Source=.;Initial Catalog=XY_JXC;User ID=sa;pwd= ";
objCn.Open();
SqlCommand cm = new SqlCommand();
cm.Connection = objCn;
cm.CommandType = CommandType.Text;
cm.CommandText = "SELECT WJIANRONG FROM B_WD_WDBIAO where ID="+id+"";
dr = cm.ExecuteReader();
byte[] File = null;
if (dr.Read())
{
File = (byte[])dr[0];//跟踪到这里有数据 }
Response.ContentType = "application/msword";
Response.OutputStream.Write(File, 0, File.Length);
}为什么点击链接加载到这页时显示的是空白页,下载页面(就是有另存为和打开取消的那个),原来时可以的啊,谢谢大家了,帮帮忙,已经试了很多方法,都没解决才来这里麻烦大家的。
{
int id = int.Parse(Request.QueryString["id"].ToString());
SqlDataReader dr = null;
SqlConnection objCn = new SqlConnection();
objCn.ConnectionString = "Data Source=.;Initial Catalog=XY_JXC;User ID=sa;pwd= ";
objCn.Open();
SqlCommand cm = new SqlCommand();
cm.Connection = objCn;
cm.CommandType = CommandType.Text;
cm.CommandText = "SELECT WJIANRONG FROM B_WD_WDBIAO where ID="+id+"";
dr = cm.ExecuteReader();
byte[] File = null;
if (dr.Read())
{
File = (byte[])dr[0];//跟踪到这里有数据 }
Response.ContentType = "application/msword";
Response.OutputStream.Write(File, 0, File.Length);
}为什么点击链接加载到这页时显示的是空白页,下载页面(就是有另存为和打开取消的那个),原来时可以的啊,谢谢大家了,帮帮忙,已经试了很多方法,都没解决才来这里麻烦大家的。
最后加个Response.End()
...........
byte[] File = null;
if (dr.Read())
{
File = (byte[])dr[0];//跟踪到这里有数据 }
Response.ContentType = "application/msword";
Response.AppendHeader("Content-Length", File.Length.ToString());//加上这个,必须的
Response.OutputStream.Write(File, 0, File.Length);
Response.ContentType = "application/msword";
//以下两句禁用页面缓存,按照六楼说的
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();
//这句也加上了,按照7楼说的
Response.AppendHeader("Content-Length", File.Length.ToString
Response.OutputStream.Write(File, 0, File.Length); 可结果怎么还是不行,在线等人帮忙,谢谢大家了