用以下代码下载excel文件的时候,在弹出筐选择【打开或保存】的时候,当打开一些内容多的excel文件的时候打开的是空或者不能打开,但保存到本地可以正常打开,什么回事呢?我尝试把Response.Flush()这句去掉,问题依旧        Response.Clear()
        Response.AppendHeader("Content-Disposition", "attachment;filename=" +        HttpUtility.UrlEncode(ModelUrl, System.Text.Encoding.UTF8))
        Response.WriteFile(ModelUrl)
        Response.Flush()   
        Response.End()

解决方案 »

  1.   

    HttpResponse response = HttpContext.Current.Response; 
    response.Clear();
    response.WriteFile(physicPath + fileName);
    string httpHeader="attachment;filename=MonthBudget.xls";
    response.AppendHeader("Content-Disposition", httpHeader);
    response.Flush();
    System.IO.File.Delete(physicPath + fileName);//删除临时文件
    response.End();
      

  2.   

    http://blog.csdn.net/sunnystar365/archive/2005/09/14/480802.aspx
    下载文件出现提示框或者直接显示在浏览器中
      

  3.   

    我知道原因了,是excel文件名问题,如果是中文的在线打开出错,但下载后一切正常,而且在弹出的【下载与保存】的筐中显示的中文文件名都是正确的,具体代码如下,请各位大侠帮忙看一下:
            Response.Clear()
            Response.ClearHeaders()
            Response.Buffer = False
            Response.Charset = "GB2312"
            Response.ContentEncoding = System.Text.Encoding.UTF8
            Response.ContentType = "application/octet-stream"
            Response.AppendHeader("Content-Disposition", "attachment;filename=" +  HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8))
            Response.AppendHeader("Content-Length", DownloadFile.Length.ToString)
            Response.WriteFile(DownloadFile.FullName)
            Response.Flush()
            Response.End()