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 在线打开 在splitcontainer控件得panel上怎么画图? C#新手提问个菜菜问题!!!!!!!!!!!! 求教如何实例华dll中的类呢?也就是如何使用动态加入的dll中的类 求一多线程遍历七位数的最优算法. 大学疑问??? 求救~~在线等!新手的菜问题!! C#如何设置双面打印PDF ***小问题***怎么取得Excel中sheet的行数? 我想做一个管理系统..出了点问题..谁来帮帮我```` richtextbox 粘贴或赋值小语种(阿拉伯文等)无显示或乱码 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 在线打开