开发者

Action required to do the operation "browse"

开发者 https://www.devze.com 2022-12-09 19:39 出处:网络
If i created a button named Browse ,,If i click Browse button开发者_如何学Python i have to browse my system folders .Can any one give me the required code to browse

If i created a button named Browse ,,If i click Browse button开发者_如何学Python i have to browse my system folders .Can any one give me the required code to browse the specific folders


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
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消