I'm trying to get the application root directory but all I can find are samples that gives the directory that includes the bin directory. I want to get just the application directory. Below is what I want to retrieve
c:\\\\project\\myproject
but what I'm getting is
c:\\\\project\\myproject\\bin\\debug
I want to remove bin\\debug
how do I do this in C# wpf?
In production the location of your app will (should) not be writable. So either make this somehow configurable, or define a fixed location, and in App startup, check if the directory and database is present - and if not, create it.
eg
var dataDir = Path.Combine(Environment.GetFolderPath(SpecialFolder.LocalApplicationData),
"MyCompany", "MyApp");
if (!Directory.Exists(dataDir))
{
Directory.CreateDirectory(dataDir);
}
var databaseFile = Path.Combine(dataDir, "MyDb.mdb");
if (!File.Exists(databaseFile ))
{
// create database
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.