zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    提高php代码效率的几点
    jquery各种操作复选框(全选、全不选、自动勾选、反选……)
    封装PDO单例模式类
    Git常用命令
    简化版的sqlserver分页
    Sql Server 数据分页
    Linux 下动态链接库搜索路径问题
    mysqlperformanceblog
    vim 退格键(backspace)不能用
    Linux vi/vim 编辑命令总结
  • 原文地址:https://www.cnblogs.com/hiflora/p/3288983.html
Copyright © 2011-2022 走看看