I've been wondering how can I browse to a directory and save the selected path to a string variable by using an console application? I have tried a few things but none seemed to work. Here's my code:
string path = "";
FolderBrowserDialog fileDialog = new FolderBrowserDialog();
var result = fileDialog.ShowDialog(); //exception
if (result == DialogResult.OK)
{
path = fileDialog.SelectedPath;
}
Console.WriteLine(path);
It throws ThreadStateException
exception at line 3
.
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."