データベースからデータを読み取り、取得したデータをExcelシートに保存し、Excelシートをダウンロードするasp .net Webアプリケーションを作成しました。これはすべて、1 回のボタン クリックで行われます。これらの手順はすべて正常に機能し、.xls ファイルをダウンロードできます。MSExcel 2007 を使用してこのファイルを開こうとすると、次の警告メッセージが表示されます。
はいをクリックすると、このファイルを開くことができます。ただし、ユーザーがファイルを開くたびにこれを行うことは望ましくありません。この警告メッセージを回避する方法を教えてもらえますか? 以下は私のソースコードです。
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();
}