C#.web 打开PDF

转自:http://blog.163.com/red_guitar@126/blog/static/11720612820112483221665/

string fileName = "201096218686";
            string p = "201096198974.pdf";//定义文件名
            string filePath = Server.MapPath("DataFile/" + p);//转换为物理路径
            Response.ClearContent();//清空缓冲区内容
            Response.ClearHeaders();//清空缓冲区HTTP头
            string FilePost = filePath.Substring(filePath.Length - 3).ToLower();//取扩展名
            switch (FilePost)
            {
                case "pdf"://PDF文件
                    Response.ContentType = "application/PDF";//设置HTTP头为PDF文档其它类似
                    break;
                case "doc":
                    Response.ContentType = "application/msword";
                    break;
                case "xls":
                    Response.ContentType = "application/vnd.ms-excel";
                    break;
                default:
                    Session["ErrorInfo"] = "不支持的文件格式:" + FilePost;
                    Response.Redirect("ErrorPage.aspx");
                    break;
            }
            Response.WriteFile(filePath);//写入客户端
            Response.Flush();//客户更新
            Response.Close();//写入关闭
            Session.Remove("Report");//移除"Report"Session

转载于:https://www.cnblogs.com/hiflora/p/3288983.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值