我在我的智慧结束。
以下代码根据查询字符串向用户显示pdf,并从文件服务器中提取pdf。它在谷歌浏览器中效果很好。但是,我也需要这个在IE中工作。
当我使用IE时,它只显示pdf应该是的空白区域。下面是我的aspx和C#文件。两个浏览器都安装了adobe reader插件。
前端:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JobBookViewer.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Job Book Viewer</title>
<style type="text/css">
#form1 {
font-weight: 700;
width: 118px;
height: 217px;
margin-top: 15px;
}
</style>
<script type="text/javascript">
function SetPDFwindow()
{
var varclientscreenwidth = screen.width;
var varclientscreenheight = screen.height;
}
</script>
</head>
<body onload="SetPDFwindow()">
<form id="form1" runat="server">
<div style="width: 203px; z-index: 1; left: 7px; top: 4px; position: relative; height: 34px; right: 811px;">
<asp:Button ID="ButtonAbout" runat="server" BackColor="#B0F1FF" style="z-index: 1; left: 873px; top: 1px; position: absolute" Text="About" OnClick="ButtonAbout_Click" Visible="false" />
<asp:ListBox ID="ListBox1" runat="server" style="z-index: 1; left: 735px; top: 41px; position: absolute; width: 206px; height: 447px;" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" AutoPostBack =" true"></asp:ListBox>
</div>
<div id="chromecheck" runat="server" visible="false">
Chrome
</div>
<div id="iecheck" runat="server" visible="false">
We have detected that you are not using Chrome. If the program is not working, please switch to Chrome
</div>
<object data="data:application/pdf;base64
, <%= this.file %>" type="application/pdf"
style="z-index: 1; left: -3px; top: 1px; height: 210%; width: 612%; margin-top: 1px;" id="myPDF"></object>
<p>
</p>
</form>
</body>
</html>
背后的代码:
using System;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
namespace JobBookViewer
{
public partial class WebForm1 : System.Web.UI.Page
{
public String file;
public String id;
protected void Page_Load(object sender, EventArgs e)
{
System.Web.HttpBrowserCapabilities browser;
browser = Request.Browser;
if (browser.Browser.ToLower().Equals("chrome"))
{
chromecheck.Visible = true;
}
else
{
iecheck.Visible = true;
}
if (!IsPostBack)
{
// myPDF.Style.Add("width", (Convert.ToInt32(clientScreenWidth.Value)-200).ToString());
file = fnFilePDFName(@"\\spfs1\stone\Long Term Share\db_objects\JobBookViewer\select_mold.pdf");
try
{
if (!String.IsNullOrEmpty(Page.Request.QueryString["MoldID"])) // if the string is not null
{
id = (Page.Request.QueryString["MoldID"]);
ListBox1.Items.Clear();
System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(@"\\spfs1\stone\mold_books\" + id.ToString());
System.IO.FileInfo[] Files = dinfo.GetFiles("*.pdf");
foreach (System.IO.FileInfo file in Files)
{
ListBox1.Items.Add(file.Name);
}
}
}
catch { }
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
file = fnFilePDFName(@"\\spfs1\stone\mold_books\" + Page.Request.QueryString["MoldID"] + @"\" + ListBox1.SelectedValue);
}
private string ModifyQueryStringValue(string p_Name, string p_NewValue)
{
var nameValues = System.Web.HttpUtility.ParseQueryString(Request.QueryString.ToString());
nameValues.Set(p_Name, p_NewValue);
string url = Request.Url.AbsolutePath;
string updatedQueryString = "?" + nameValues.ToString();
return url + updatedQueryString;
}
public string fnFilePDFName(string path)
{
string sfileContent;
Byte[] bytes = File.ReadAllBytes(path);
sfileContent = Convert.ToBase64String(bytes);
return sfileContent;
}
}
}