源自:邀月 (个人网站)
本例演示了如何从文件中检索二进制数据,然后如何使用 ASP.NET 和 Visual C# 将该数据写出到浏览器中。尽管此演示使用的是 Adobe Acrobat (.pdf) 文件(Web 应用程序开发人员常使用这种文件),但您也可以对其他二进制文件格式使用此过程。
1、确保要从其上查看 .aspx 页的客户端计算机上已安装了 Adobe Acrobat Reader,以便浏览器能够正确读取并呈现二进制数据。可以从以下 Adobe 网站下载 Adobe Acrobat Reader:
在代码隐藏页的 Page_Load 事件中,加入以下代码: private void Page_Load(object sender, System.EventArgs e)![]() ...{ //Set the appropriate ContentType. Response.ContentType = "Application/pdf"; //Get the physical path to the file. string FilePath = MapPath("acrobat.pdf"); //Write the file directly to the HTTP content output stream. Response.WriteFile(FilePath); Response.End(); } |
最新相关文章
发表评论