下载文件不适用于IE11

时间:2015-10-20 12:58:36

标签: c# asp.net

我尝试使用浏览器下载文件。此代码适用于Chrome和Firefox,但不适用于IE11。

string fileName = context.Request.QueryString["fileName"];
int dateArrete = 0;

if (!String.IsNullOrEmpty(fileName) && !String.IsNullOrEmpty(numCompte) && !String.IsNullOrEmpty(societe) && !String.IsNullOrEmpty(arrete) && Int32.TryParse(arrete, out dateArrete))
{
    Revision revision = RevisionGestion.Get(numCompte, dateArrete, societe);
    string extension = fileName.Substring(fileName.LastIndexOf('.') + 1);

    context.Response.Clear();
    switch (extension)
    {
        case "xls": context.Response.ContentType = "application/ms-excel"; break;
        case "doc": context.Response.ContentType = "application/msword"; break;
        case "pdf": context.Response.ContentType = "application/pdf"; break;
        default: context.Response.ContentType = "application/octet-stream";  break;
    }
    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
    context.Response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    context.Response.AddHeader("Pragma", "no-cache");
    context.Response.AddHeader("Expires", "0");

    context.Response.WriteFile(revision.RepertoirePieceJointe + fileName);
    context.Response.Flush();
    context.Response.Close();
    context.ApplicationInstance.CompleteRequest();

错误是:

  

无法下载文件

有人有任何建议吗?

0 个答案:

没有答案
相关问题