Reputation: 23
I am trying to check my db file existence in try block and in catch I am creating it.
public async Task<bool> CheckDbAsync()
{
bool dbExist = true;
try
{
StorageFile sf = await ApplicationData.Current.LocalFolder.GetFileAsync(DB_NAME);
}
catch(FileNotFoundException)
{
Conn = new SQLiteAsyncConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path,"baby.db") , true);
dbExist = false;
}
return dbExist;
}
Issue is I am getting same handled exception. Code breaks on my try block. Any idea why?
Upvotes: 1
Views: 158
Reputation: 23
I have fixed the issue by using
System.IO.File.Exists(string.Format(@"{0}\{1}", ApplicationData.Current.LocalFolder.Path, DB_NAME));
which returns a bool if file exists or not.
Regards.
Upvotes: 0
Reputation: 938
If you want to check file existance, you can use TryGetItemAsync() like this:
StorageFile sf = await ApplicationData.Current.LocalFolder.TryGetItemAsync(DB_NAME);
Upvotes: 2