Folderdialog in Consoleapplication C#

Asked

Viewed 21 times

3

I am with a question related to Console Application, as I do to open a window similar to this where it is possible to select a FOLDER? inserir a descrição da imagem aqui

It would be a resource like the one in Windowsforms where it is Folderbrowserdialog.

I use the . NET Framework 4.5.

1 answer

2


Do so,

Just instantiate and call.

static class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        FolderBrowserDialog fbd = new FolderBrowserDialog();
        if (fbd.ShowDialog() == DialogResult.OK)
        {
            foreach (var path in Directory.GetFiles(fbd.SelectedPath))
            {
                Console.WriteLine(path); // full path
                Console.WriteLine(System.IO.Path.GetFileName(path)); // file name
            }
        }


    }
}

Source: https://stackoverflow.com/questions/15270387/browse-for-folder-in-console-application

MUST ADD THE REF. to System.Windows.Forms

as our friend @Iago Correia Guimarães recalled well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.