I'm trying to add a SQLite database to my .NET MAUI app, but cannot get the path of the database file.
When I add a break point at this code
string dbpath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"clientdb.db3");
the dbpath variable is null when debugging the app and the table method does not display anything.
I've tried changing LocalApplictionData into CommonApplicationData and also MyDocuments, but it does not work.
the rest of the code is:
public SQLiteAsyncConnection _dbConnection;
public SqlightServiceClass()
{
CreatSqlightConnection();
}
public async void CreatSqlightConnection()
{
if (_dbConnection == null)
{
string path1 = FileSystem.Current.AppDataDirectory;
string dbpath = Path.Combine(path1, "Employees.db3");
_dbConnection = new SQLiteAsyncConnection(dbpath);
await _dbConnection.CreateTableAsync<ClientInfoModel>();
}
}
LocalApplicationDatais a path in the WIndows OS. It might not be available on the OS you are using.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)return null?