I’m developing an app that connects to a MS Access database. The path to the database is stored in a string and can be changed by user at any time because the database can be placed anywhere in the hard disc. The app must save the path to the database in a configuration file.
How can I read and write this configuration file and have no problems with user privileges? Must I save the configuration file in the same Programs Folder than my app or in a user specific folder? What if I user a ini file or a xml file?
This is the logic of my app:
myOpenFileDialog.Filter = "MS Access Database|*.mdb";
if (myOpenFileDialog.ShowDialog() == DialogResult.OK)
{
string pathBD = myOpenFileDialog.FileName;
if (File.Exists(pathBD))
{
// save pathBD to a configuration file
// next time when the app loads
// it will read the configuration file
// and look for the database in the given path
}
}
Use the Settings class. You can save this as a user setting and then each user can have their own path, or you set it as an application setting and it will be used by all users.