Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the last opened file in fileopen dialog box

Tags:

c#

In FileOpen or FileSave dialogbox when I call them, they automatically go to the last opened path. This happens even if I close my application and open it. But how to get that path/file name to a textbox or variable?

like image 563
Vicky Avatar asked Apr 19 '11 09:04

Vicky


2 Answers

it seems a bit weired but under Windows 7 it works with the folling:

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);

Try it and tell me if you need further help.

like image 74
bastianwegge Avatar answered Sep 22 '22 04:09

bastianwegge


Presumably the information is stored somewhere in the depths of the registry (it's done by the unmanaged control to which OpenFileDialog is only a wrapper). The easiest would probably be to persist the path the last time the dialog was closed in your application somewhere where you can access it.

like image 43
ChrisWue Avatar answered Sep 20 '22 04:09

ChrisWue