Paste directory path

3

I want to get a system directory, open a window and in this window I select a directory. I can select files with OpenFileDialog but no directories.

    
asked by anonymous 11.12.2014 / 16:08

2 answers

3

You can use the FolderBrowserDialog :

// Instancia a classe.
using (FolderBrowserDialog dirDialog = new FolderBrowserDialog())
{
    // Mostra a janela de escolha do directorio
    DialogResult res = dirDialog.ShowDialog();
    if (res == DialogResult.OK)
    {
        // Como o utilizador carregou no OK, o directorio escolhido pode ser acedido da seguinte forma:
        string directorio = dirDialog.SelectedPath;
    }
    else
    {
        // Caso o utilizador tenha cancelado
        // ...
    }
}

In addition to basic use it can also allow the user to create directories through the window. To do this, place the following property at true :

dirDialog.ShowNewFolderButton = true;

You can also decide which directory to choose when the window is opened. To do this, use the FolderBrowserDialog.RootFolder property.

    
11.12.2014 / 16:41
1

Instead of using OpenFileDialog use the folderBrowserDialog control

Source

link

    
11.12.2014 / 16:19