You should build your paths using the
Path.Combine
method. It will automatically take care of path separators for you.
string basePath = @"C:\ProgramData";
string appDir = Path.Combine(basePath, "MyApp");
string dbDir = Path.Combine(appDir, "DB");
string osDir = Path.Combine(appDir, "OS");
string dbFile = Path.Combine(dbDir, "Allfiles.mdb");
Also note the extra
@
in front of the opening double-quote for the string declaration. It tells the compiler that backslash should not be interpreted as an escape character as it would normally do, but rather as the literal backslash character itself. It allows for specifying paths without the need to double the backslashes:
string basePath = @"C:\ProgramData";
string basePath = "C:\\ProgramData";
Regarding the database-storage part, you can save any path, or part of a path, as a string.
Finally, if you want to change the path of the database in the application, you have to do it before connecting to the database. If there is an active connection, you would have to close it, change the path, and then open the connection on the new database.