peter
peter

Reputation: 8682

Action required to do the operation "browse"

If i created a button named Browse ,,If i click Browse button i have to browse my system folders .Can any one give me the required code to browse the specific folders

Upvotes: 0

Views: 1285

Answers (2)

itsmatt
itsmatt

Reputation: 31416

Check out the FolderBrowserDialog if you are wanting to find a folder. If you are wanting to open a file, you can use the OpenFileDialog.

Both links provide examples of how to use the dialogs.

This MSDN link provides how to get the special system folders. And you can specify the type of special folder you want by using the appropriate enumeration. Check this link for those.

Essentially, you are going to do something like so if you want to pop up a dialog and browse to the System folder and select some files from there:

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog od = new OpenFileDialog();
    od.InitialDirectory = Environgment.SpecialFolder.System;
    od.Multiselect = true;
    if (od.ShowDialog() == DialogResult.OK)
    {
       // do stuff
       // od.Filenames will hold the string[] of selected files
    }
}

Upvotes: 2

Foxfire
Foxfire

Reputation: 5765

Assuming you want to display the results in a list named files something like:

String directory = Environment.GetFolderPath (Environment.SpecialFolder.System);
String[]files = Directory.GetFiles (directory);
foreach (String file in files)
  files.Add (file);

You can use a FolderBrowserDialog control and call the code there if you want to browse multiple directories.

Upvotes: 0

Related Questions