Reputation: 21260
I want to store last file paths that user opened via the application. And on next opening of the application to present it back to him.
What is the recommended way doing so in WPF application ?
Thanks for help.
Upvotes: 0
Views: 1986
Reputation: 216293
Add a Settings file to your application through the Project Properties and Settings Tab.
Name this settings LastUserSelectedPath
, select a String Type, and most important, choose a User setting. Leave the Value empty.
Now, in your application, you could read this property using
string uPath = Properties.Settings.Default.LastUserSelectedPath;
and you can write it back with
string newSelectedPath = SomeMethodThatReturnsTheNewPath();
Properties.Settings.Default.LastUserSelectedPath = newSelectedPath;
Properties.Settings.Default.Save();
Note that this works per user basis. A different user, also if it runs on the same machine, will have a different setting.
Don't forget to add the
using System.Configuration;
Upvotes: 3
Reputation: 69372
If you're using the OpenFileDialog control, you can set the RestoreDirectory property to true
before calling ShowDialog. I believe this stores the last directory for you in the registry but only if the user clicks OK
rather than Cancel
.
Upvotes: 0