title: How to open a pdf file in a WebForm application by search?
body: <p>When I click on the listbox which search a PDF file, it's not opening.</p>
  
  <p>The code is below. Any thoughts?</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(file);
        ListBox1.Items.Add(Path.GetFileName(file));
      }
    }
    else
    {
      Response.Write("&lt;script&gt;alert('For this Wafer ID Report is Not Generated');&lt;/script&gt;");
    }
  }
  
  protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
    string pdffiles = ListBox1.SelectedItem.ToString();
  
    string.Format("attachment; filename={0}", fileName));
  
    ProcessStartInfo infoOpenPdf = new ProcessStartInfo();
    infoOpenPdf.FileName = pdffiles;
    infoOpenPdf.Verb = "OPEN";
    // Process.Start(file);
    infoOpenPdf.CreateNoWindow = true;
    infoOpenPdf.WindowStyle = ProcessWindowStyle.Normal;
  
    Process openPdf = new Process();
    openPdf.StartInfo = infoOpenPdf;
    openPdf.Start();
  }
  </code></pre>