Ruben
Ruben

Reputation: 6427

Set OpenFolderDialog to a special folder

I know it is possible to set the current folder of the OpenFolderDialog to a special folder, like "Program Files" or Desktop?

But where do I find this?

Upvotes: 1

Views: 5806

Answers (3)

peSHIr
peSHIr

Reputation: 6370

You could simply set the initial folder of the OpenFolderDialog to the result of System.Environment.GetFolderPath().

Upvotes: 1

M4N
M4N

Reputation: 96606

Look at the System.Environment class, e.g:

string programFiles = System.Environment.GetFolderPath(
     System.Environment.SpecialFolder.ProgramFiles);

Update:

I'm not sure if this is part of the question, but to open the folder selection dialog, you then use this code:

using System.Windows.Forms;

//...

FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.SelectedPath = programFiles;
dialog.ShowDialog();

string selectedPath = dialog.SelectedPath;

Upvotes: 11

John Källén
John Källén

Reputation: 7983

Have you tried setting the folder to System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)? This should do the trick.

Upvotes: 3

Related Questions