3

I want to open application directory with button click. i get such error

enter image description here

Does anyone have an idea?

CodeWarrior
  • 7,388
  • 7
  • 51
  • 78
Irakli Lekishvili
  • 33,492
  • 33
  • 111
  • 169

3 Answers3

5

If you set UseShellExecute to true, then you can use Process to open a directory. For example, this will open the C:\ drive. You can specify any path you want.

Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = @"C:\";
process.Start();

This is similar to using the Run dialog from the start menu. For instance, even though a Word document is not a program, using Shell Execute will allow you to "Start" a word document by using whatever program is associated with it. Likewise the same with a directory.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
1

Have you tried "explorer.exe {0}" ? Explorer is the process you want, and the argument your intended path.

CodeWarrior
  • 7,388
  • 7
  • 51
  • 78
  • It is possible for some whacko to rename his Explorer.exe to AnythingElse.exe, though... – Devin Burke Aug 25 '11 at 16:09
  • 1
    It is indeed, but then said wacko is not going to have a Windows desktop. Sure, they could run LightStep or something like that as a replacement desktop; but renaming it would also cause problems to their local system. – CodeWarrior Aug 25 '11 at 16:11
  • Actually, [this SO answer](http://stackoverflow.com/questions/1132422/c-open-folder) suggests that what s/he is trying to do should work. The only difference I see is the \ at the end. – Devin Burke Aug 25 '11 at 16:13
0

Try setting the ProcessStartInfo.Verb to "Open".

Philipp Schmid
  • 5,778
  • 5
  • 44
  • 66