开发者

Download PDF Document on Save as dialog

I am using following code for downloading PDF document in save as mode but there is a problem in IE, anyone can resolve this prohlem?

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 (e开发者_开发问答xt != 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();
    }

}

thanks

Asim Hashmi


Maybe because you're using SSL?
check this: http://support.microsoft.com/kb/316431

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜