0

I am using a non win forms program where I need to open the file explorer and return the file that the user selects. I am using Process.Start("explorer.exe", "/select etc"); to open file explorer, but when I select a file it just opens that file. Is there a way that when I select the file it will return the file path to a variable?

Aaron
  • 4,380
  • 19
  • 85
  • 141
  • 1
    Possible duplicate of [How do I add a form to a console app so that user can select file?](http://stackoverflow.com/questions/12553932/how-do-i-add-a-form-to-a-console-app-so-that-user-can-select-file) – NineBerry Mar 22 '16 at 17:47

1 Answers1

3

I'm sure your approach is wrong. As the documentation[1] states:

/select, Opens a window view with the specified folder, file or application selected.

So the /select command line argument only tells the explorer to pre-select the specified folder or file. It is not for returning any user selection.

I suggest to use OpenFileDialog. You can use this dialog even if your application is not a pure Windows Forms app. You just need to reference the needed assemblies (System.Windows.Forms.dll) and namespaces (using System.Windows.Forms;).


[1] Link outdated: archive

René Vogt
  • 43,056
  • 14
  • 77
  • 99