Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,

Currently i'm doing a web application project in ASP.net C#.

Here i have a problem to search a file by its name. Below code is shows were i did, but the problem is, it does not shows the file according to the search name, since it show all file name in directories.

Another problem is, i don't how to open the search files. Can any one help me?

C#
protected void Button1_Click(object sender, EventArgs e)
        {


            if (TextBox1.Text != "")
            {
                string[] pdffiles = Directory.GetFiles(@"\\192.168.5.10\\fbar\\REPORT\\CLOTHO\\H2\\REPORT\\", "*.pdf", SearchOption.AllDirectories);
                string search = TextBox1.Text;
                ListBox1.Items.Clear();
                foreach (string file in pdffiles)
                {

                    ListBox1.Items.Add(Path.GetFileName(file));
                }

                TextBox1.Focus();
            }
            else
            {
                Response.Write("<script>alert('For this Wafer ID Report is Not Generated');</script>");


            }
        }
Posted

string[] pdffiles = Directory.GetFiles(@"\\192.168.5.10\\fbar\\REPORT\\CLOTHO\\H2\\REPORT\\", "*" + TextBox1.Text + "*.pdf",SearchOption.AllDirectories);
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 25-Sep-15 2:18am    
5
DamithSL 25-Sep-15 2:30am    
thank you :)
CgKumar 25-Sep-15 2:36am    
Thanks it is work. But can you give me a sample code for open the .pdf file from the ListBox1. Please help me...
Thanks7872 25-Sep-15 5:02am    
We are not a code provider service. Try it and do it yourself. He is providing you some help and still you are asking for codes again. Doesn't make much sense.
CgKumar 30-Sep-15 5:43am    
Thanks... ;)
This code will open the PDF file using the default reader.

Put the code below into one of the events of the list box, for example, DoubleClick.
C#
ProcessStartInfo infoOpenPdf = new ProcessStartInfo();
infoOpenPdf.Verb = "open";
infoOpenPdf.FileName = pathPdf;
infoOpenPdf.CreateNoWindow = true;
infoOpenPdf.WindowStyle = ProcessWindowStyle.Normal;

Process openPdf = new Process();
openPdf.StartInfo = infoOpenPdf;
openPdf.Start();

Add the following to the top of the source file:
C#
using System.Diagnostics;
 
Share this answer
 
v4
Comments
CgKumar 25-Sep-15 3:58am    
have error at ProcessStartInfo, is that i'm need to add any references...?? Please help me...
George Jonsson 25-Sep-15 8:56am    
add
using System.Diagnostics;

At least try using Google once in your life.
CgKumar 27-Sep-15 20:58pm    
Thank you George. I'm already did what you mention. But my bad is the pdf file is still cannot open. Is that had any problem in my below code. Please give me any suggestion. Thank you.

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)

{
string file = ListBox1.SelectedItem.ToString();

ProcessStartInfo infoOpenPdf = new ProcessStartInfo(file);
infoOpenPdf.Verb = "open";
infoOpenPdf.FileName = file;
infoOpenPdf.CreateNoWindow = true;
infoOpenPdf.WindowStyle = ProcessWindowStyle.Normal;

Process openPdf = new Process();
openPdf.StartInfo = infoOpenPdf;
openPdf.Start();
}
George Jonsson 28-Sep-15 0:37am    
Do you have Acrobat Reader installed on your computer?
CgKumar 28-Sep-15 4:29am    
Yes i already have the Acrobat Reader...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900