title: How to Open the PDF file in new tab using c#?
body: <p>Here i have problem to open the selected PDF file in new tab of browser. In below is shows the code were i done. Can anyone help me...please...</p>
  
  <p>Search Button:</p>
  
  <pre><code>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("&lt;script&gt;alert('For this Wafer ID Report is Not Generated');&lt;/script&gt;");
                      }
                  }
  </code></pre>
  
  <p>PDF file open Button:</p>
  
  <pre><code>            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("&lt;script&gt;alert('PDF File is not Selected');&lt;/script&gt;");
                              }
                  }
              }
  </code></pre>