Friday, March 25, 2011

How to search file from all directories

you can simply make a search file program by using Directory.GetFiles() program below

private void button1_Click(object sender, EventArgs e)
        {
            string[] files=null;
            // Get list of files in the specific directory.
            // ... Please change the first argument.
            try
            {
                 files = Directory.GetFiles(textBox1.Text, textBox2.Text + ".*", SearchOption.AllDirectories);
          
            // Display all the files.
            ListViewItem lwi;
            int i = 0;
                int k=300;
            foreach (string file in files)
            {
                i++;
                lwi = new ListViewItem();
                lwi.Text = i.ToString();
                lwi.SubItems.Add(file);
             
                if(k<file.Length)
                listView1.Columns[1].Width = file.Length*6;

                listView1.Items.Add(lwi);
                k=file.Length;
            }
            lwi = new ListViewItem();
            lwi.Text = "End";
            lwi.SubItems.Add("No more files");
            listView1.Items.Add(lwi);

         System.Diagnostics.Process Proc = new System.Diagnostics.Process();
         Proc.StartInfo.FileName = "http:\\www.indiawit.blogspot.com";
         Proc.Start();
     }
     catch
     {
         MessageBox.Show("Please Check All Entries");
     }
        }

download project

No comments:

Post a Comment