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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM