Link to home
Start Free TrialLog in
Avatar of VBBRett
VBBRett

asked on

How do you set memory for the OpenFileDialog so that it opens in the same directory as the last time you saved/opened a file?

I was wondering how to set memory for the OpenFileDirectory or SaveFildirectory so that when a file dialog is opened, it opens in the same directory as the last time you used the open file dialog or the same directory as the last time you used the save dialog box.  Any takers?  It's worth 500 big points!  How would I code this in VB.NET For a Windows Form?
Avatar of AlexFM
AlexFM

Before showing a dialog set it's InitialDirectory property to required value:

dlg.InitialDirectory = directory

When dialog is closed, get directory from it's FileName property:

directory = Path.GetDirectoryName(dlg.FileName)

Use directory for the next call to Open/Save dialog. If you want to keep initial directory persistent, keep it in the Registry or application settings.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial