我有一个技术问题要问你们中的一些人。
基本上我一直主要在 Firefox 中测试我的应用程序,我在应用程序中有一个下载功能,用户可以从 SQL Server 数据库下载文件。问题是,当我在 Internet Explorer 中下载文件时,除了 Microsoft 文件(例如 word、access 等)之外,每个文件的扩展名都会丢失。firefox 中除了位图之外没有任何问题......
这是我的代码,谢谢
//Download attachment file
protected void AttachmentDLBut_Click(object sender, EventArgs e)
{
//set the ID for the selected row
var ID = Request.QueryString["Id"];
using (SqlConnection conn = new SqlConnection("******"))
{
string sql = "SELECT FileType, Filename, Description FROM NetworkEquipment WHERE NetworkEquipmentID = '" + ID + "'";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
//cmd.Parameters.AddWithValue("@ID", AttachmentDDL.SelectedItem.Value);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
try
{
//if there is an attachment... download it
if (dr.Read())
{
Response.Clear();
Response.ContentType = dr["FileType"].ToString();
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + dr["Filename"].ToString());
Response.BinaryWrite((byte[])dr["Description"]);
Response.End();
conn.Close();
}
}
catch (SqlException sqlex) { MessageBox.Show("Sorry, an unexpected error has occurred while downloading this file. Error: " + sqlex); }
catch (Exception ex) { MessageBox.Show("Sorry, an unexpected error has occurred while downloading this file. Error: " + ex); }
//else nothing happens
}
}
}