below is my code to open a database in a user-selected folder
SqliteConnection db;
public async Task<string> openDatabase(String databaseFilename)
{
db = new SqliteConnection($"Filename={databaseFilename}");
await db.OpenAsync();
return null;
}
//...
var folderPicker = new FolderPicker();//must-use broker in UWP
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
string encryptedUserSelectedFolderString = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(folder);
//...
StorageFolder fd = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(encryptedUserSelectedFolderString);//user-selected folder
var t = await fd.TryGetItemAsync("data.data");//sqlite in the folder
if (t != null)
{
db.openDatabase(Path.Combine(fd.Path,"data.data"));//this line causes app freezing
}
it reports the error:
unable to open the database file
...but the same code:
StorageFolder fd = await StorageFolder.GetFolderFromPathAsync(ApplicationData.Current.LocalFolder.Path);
var t = await fd.TryGetItemAsync("data.data");
db.openDatabase(Path.Combine(fd.Path, "data.data"));//open database correctly
...can open the database in ApplicationData.Current.LocalFolder
without any problem
Just wondering if there is a special requirement to open the database in the user-selected folder?
--------------------------------------------------updated question
my code to open a png file in the sub folder of the user-selected folder
Task<StorageFolder> folder = folderForBookmark(encryptedUserSelectedFolderString);
StorageFolder bbb =await folder;
StorageFile aaa = await bbb.GetFileAsync( "subfolder\\1.png");
IRandomAccessStream fileStream = await aaa.OpenAsync(Windows.Storage.FileAccessMode.Read);
//*create Bitmap from filestream
BitmapImage bmpImage = new BitmapImage();
bmpImage.SetSource(fileStream);
//load bitmap into image-control
aImage.Source = bmpImage;
it works! it can load the image file