OpenFileDialog. How about a "Specify Dialog"?

In the file path field, I want to capture the directory path, for example:

textbox1.Text = directory path

Is anyone

+3
source share
3 answers

Well, I am using VS 2008 SP1. It's all I need:

private void button1_Click(object sender, EventArgs e)
{
    FolderBrowserDialog profilePath = new FolderBrowserDialog();

    if (profilePath.ShowDialog() == DialogResult.OK)        
    {
        profilePathTextBox.Text = profilePath.SelectedPath;
    }
    else
    {
        profilePathTextBox.Text = "Please Specify The Profile Path";
    }
}
+4
source

There is a FolderBrowserDialog class that you can use if you want the user to select a folder.

http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx

DialogResult result = folderBrowserDialog1.ShowDialog();
if (result.Equals(get_DialogResult().OK)) {
    textbox1.Text = folderBrowserDialog1.get_SelectedPath();
}

If all you need to do is get the directive from the full path, you can do this:

textbox1.Text = Path.GetDirectoryName(@"c:\windows\temp\myfile.txt");

This will set the Text property to "c: \ windows \ temp \"

+10
source

If you don’t need a scary, non-user-friendly dialog *, try Ookii.Dialogs or see other answers on How to configure OpenFileDialog to select folders? . The only drawback that I see in Ookii is that it requires .NET 4 Full, not just the client profile. But the source is included in the download, so I will work on it. Too bad that the license is not LGPL or similar ...

See also: WinForms message box with text buttons

* Here is what FolderBrowserDialog looks like:

Ugly, unfriendly folder browser dialog

0
source

Source: https://habr.com/ru/post/1697030/


All Articles