在这里,我使用网格单击的行命令事件下载了一个 word/doc 文件,然后我编写了一个方法 downloadresume。这种方法在所有浏览器中都可以正常工作,除了 IE 中的 Internet Explorer 生成 .aspx 而不是文件。任何人都可以帮我解决这个问题
protected void grdCandidate_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "Download")
{
byte[] Attachment = null;
string Extension = string.Empty;
ClsCandidateManager objCandidateManager = new ClsCandidateManager();
Attachment = objCandidateManager.GetCandidateAttachment(Convert.ToInt32(e.CommandArgument), out Extension);
DownloadAttachment("Resume", Attachment, Extension);
}
}
catch (Exception ex)
{
string str = ex.Message + ex.InnerException;
}
}
public void DownloadAttachment(string strFileName, byte[] Attachment, string Extension)
{
if (Attachment != null && Attachment.Length > 0)
{
Page.Response.Clear();
Page.Response.Buffer = true;
Page.Response.Charset = "";
if (Extension == ".pdf")
{
Page.Response.ContentType = "application/pdf";
}
else
{
Page.Response.ContentType = "application/vsd-msword";
}
Page.Response.AddHeader("content-disposition", "attachment;filename=" + strFileName + Extension);
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Page.Response.BinaryWrite(Attachment);
Page.Response.Flush();
//Response.End();
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "Attachment", "alert('Attachment not found!');", true);
}
}