在“另存为”对话框中下载PDF文档

时间:2010-11-03 13:55:42

标签: asp.net

我在保存模式下使用以下代码下载PDF文档,但IE中存在问题, 任何人都可以解决这个问题吗?

private void DownloadFile(string fname, bool forceDownload)
{
    string path = MapPath(fname);
    string name = Path.GetFileName(fname);
    string ext = Path.GetExtension(fname);
    string type = "";
    Response.ClearHeaders();
    Response.ClearContent();
    // set known types based on file extension  
    if (ext != null)
    {
        switch (ext.ToLower())
        {
            case ".htm":
            case ".html":
                type = "text/HTML";
                break;

            case ".txt":
                type = "text/plain";
                break;

            case ".pdf":
               type = "application/pdf";
                break;
            case ".doc":
            case ".docx":
            case ".rtf":
                type = "Application/msword";
                break;
        }
    }
    if (forceDownload)
    {
        Response.AppendHeader("content-disposition", "attachment; filename=" + name);
    }
    if (type != "")
    {
        Response.ContentType = type;
        Response.WriteFile(path);
        Response.End();
    }

}

感谢

Asim Hashmi

1 个答案:

答案 0 :(得分:0)

也许是因为你使用的是SSL? 检查一下:http://support.microsoft.com/kb/316431