1

I'm developing a program in c# im stuck with this issue.

I want to show dialog box which refers to a particular directory.

I know that there is OpenDialogFolder and SaveDialog, but I don't want to save or open any files what I want is just to open a specific directory dialog box.

Like this screenshot:

enter image description here

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Scorpio
  • 153
  • 1
  • 5
  • 13

1 Answers1

3

It looks like you just want to open a copy of Windows Explorer. You can do that by simply calling Process.Start() and specifying just a folder path with no filename:

Process.Start(@"C:\Temp\");

The default behavior of the Windows shell, given a command like this on the command line (or a shortcut or a Run command) is to open Windows Explorer to show the contents of the specified path.

Now, Windows Explorer is an external process, which you are launching and then letting it do its thing. It therefore won't behave exactly like a modal dialog box, like preventing the dialog losing focus to another window. However, you can mimic the "can't do anything else with the application" behavior of a dialog by assigning the result of Process.Start (a Process) to a variable, then calling the WaitForExit() method on that Process with no parameters. This will block the application's main thread until the user closes the Explorer window you opened. It's not perfect; by blocking the thread, the application will not respond to any requests to draw itself or do any other basic things that even a dialog-interrupted window will still do, and you can still technically "activate" the window you used to launch Windows Explorer which will bring it in front of Windows Explorer. The Explorer window can also be minimized (something dialogs don't normally allow) and there isn't much you can do to prevent that.

KeithS
  • 70,210
  • 21
  • 112
  • 164
  • No worries @LarsTech; your answer was what I originally thought of as well until I saw his screenshot. – KeithS Aug 31 '12 at 19:10