[英]How to Open the PDF file in new tab using c#?
Here i have problem to open the selected PDF file in new tab of browser. 在这里,我在浏览器的新标签页中打开选定的PDF文件时遇到问题。 In below is shows the code were i done.
在下面显示的代码是我完成的。 Can anyone help me...please...
谁能帮我...请...
Search Button: 搜索按钮:
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
string search = TextBox1.Text;
if (TextBox1.Text != "")
{
string[] pdffiles = Directory.GetFiles(@"\\192.168.5.10\fbar\REPORT\CLOTHO\H2\REPORT\","*"+ TextBox1.Text + "*.pdf", SearchOption.AllDirectories);
foreach (string file in pdffiles)
{
ListBox1.Items.Add(new ListItem(Path.GetFileName(file), file));
}
}
else
{
Response.Write("<script>alert('For this Wafer ID Report is Not Generated');</script>");
}
}
PDF file open Button: PDF文件打开按钮:
protected void Button2_Click(object sender, EventArgs e)
{
try
{
string fileName = ListBox1.SelectedValue;
byte[] fileBytes = System.IO.File.ReadAllBytes(fileName);
WebClient User = new WebClient();
Byte[] FileBuffer = User.DownloadData(fileName);
if (FileBuffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);
}
}
catch(Exception ex)
{
Response.Write("<script>alert('PDF File is not Selected');</script>");
}
}
}
You would need to inject some javascript code: 您需要注入一些javascript代码:
Response.Write("<script>window.open('" + pdf_filepath + "','_blank')</script>");
That should work :D 那应该工作:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.