asp.net IE 中直接打开 Excel 文件,不要弹出对话框 asp.net IE 中直接打开 Excel 文件,不要弹出对话框每一次都弹出打开,还是保存的确认对话框很麻烦,想要按按钮后就直接打开一个excel文件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int id= Convert.ToInt32( Request.QueryString["docId"],10); string ConnStr=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; string str_get_file="select * from fmfilecont where fileid="+id; SqlConnection Conn = new SqlConnection(ConnStr); SqlCommand myCommand=new SqlCommand(str_get_file,Conn); Conn.Open(); SqlDataReader dr = myCommand.ExecuteReader(); if(dr.Read()) { Response.ContentType = (string)dr["ftype"]; Response.OutputStream.Write((byte[])dr["cont"], 0, (int)dr["Size"]); } else { Response.Write("没有这个文件"); Response.End(); } dr.Close(); myCommand.Connection.Close(); 这个与客户端设置有关但可以设置Content-type等http头试试 我记得是这样设置IIS--》右键默认网站--》HTTP头--》文件类型--》新类型--》 // System.IO.FileInfo fileExcel = new System.IO.FileInfo(serverPath); int a = serverPath.LastIndexOf("\\") + 1; string fileName = serverPath.Substring(a, serverPath.Length - a); System.IO.FileStream fs = new System.IO.FileStream(serverPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] bFile = new byte[fs.Length]; System.IO.BinaryReader r = new System.IO.BinaryReader(fs); bFile = r.ReadBytes((int)fs.Length); r.Close(); r = null; fs.Close(); Response.Clear(); Response.Buffer = true; Response.Charset = "GB2312"; Response.AppendHeader("Content-Disposition", "online ;filename=" + Server.UrlEncode(fileName)); //把 attachment 改为 online 则在线打开 //Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + Server.UrlEncode(fileName) + "\""); Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//utf-8 Response.ContentType = "application/ms-excel"; Page.EnableViewState = false; Response.BinaryWrite(bFile); Response.Flush(); Response.End(); attachment 提示 online 在线打开 关于ComboBox和DateTimePicker控件的几个问题 向 system32 目录写入文件 匹配字符串 vs2005 中读取web.config 中的连接字符串 请问:怎么样才能返回多个值??? 急需解决问题 OleDbDataAdapter更新数据,请看看有什么更好的方案?OleDbDataAdapter跨表更新,多表更新 此位置仅允许 <siteMapNode> 元素 用chart 控件绘图怎么获取曲线颜色 “斑竹”及各位大虾救命啊!!!!!(Socket 问题) winform读取和配置CSS式样 如何保持div的滚动条在底端?
string ConnStr=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
string str_get_file="select * from fmfilecont where fileid="+id;
SqlConnection Conn = new SqlConnection(ConnStr);
SqlCommand myCommand=new SqlCommand(str_get_file,Conn);
Conn.Open(); SqlDataReader dr = myCommand.ExecuteReader(); if(dr.Read())
{
Response.ContentType = (string)dr["ftype"];
Response.OutputStream.Write((byte[])dr["cont"], 0, (int)dr["Size"]);
}
else
{
Response.Write("没有这个文件");
Response.End();
} dr.Close();
myCommand.Connection.Close();
IIS--》右键默认网站--》HTTP头--》文件类型--》新类型--》
int a = serverPath.LastIndexOf("\\") + 1;
string fileName = serverPath.Substring(a, serverPath.Length - a); System.IO.FileStream fs = new System.IO.FileStream(serverPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] bFile = new byte[fs.Length];
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
bFile = r.ReadBytes((int)fs.Length);
r.Close();
r = null;
fs.Close(); Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "online ;filename=" + Server.UrlEncode(fileName)); //把 attachment 改为 online 则在线打开
//Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + Server.UrlEncode(fileName) + "\"");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//utf-8
Response.ContentType = "application/ms-excel";
Page.EnableViewState = false;
Response.BinaryWrite(bFile);
Response.Flush();
Response.End();
online 在线打开