0
我已经创建了一个asp.net网络应用程序,它从数据库中读取数据,将检索到的数据存储在Excel表格中并下载Excel表格。所有这一切发生在一次单击按钮。所有这些步骤工作正常,我可以下载.xls文件。当我尝试使用MSExcel 2007打开此文件时,我收到以下警告消息。 无法打开使用asp.net应用程序下载的.xls文件
如果我点击是,我将能够打开此文件。但是,我不希望我的用户在每次打开文件时都这样做。有人能告诉我如何避免这个警告信息?以下是我的源代码。
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["EMS_SMSConnectionString"].ToString()))
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from accessories", con);
// cmd.Parameters.AddWithValue("id", GridView1.SelectedRow.Cells[1].Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
// to open file prompt Box open or Save file
Response.AddHeader("content-disposition", "attachment;filename=mridul.xls");
Response.Charset = "";
System.Text.Encoding enc = System.Text.Encoding.ASCII;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
byte[] myByteArray = enc.GetBytes(dr["AccessoriesName"].ToString());
Response.BinaryWrite(myByteArray);
Response.End();
}
用户不得不取消Word中的安全警告 – kobe 2013-04-23 13:18:49