I'm having a weird issue with the FilePicker on UWP and I'm not sure what's causing this.
I'm saving/loading a file using the FilePicker:
private static IAsyncOperation<StorageFile> PickFileAsync()
{
FileOpenPicker picker = new FileOpenPicker
{
ViewMode = PickerViewMode.List,
SuggestedStartLocation = PickerLocationId.ComputerFolder
};
picker.FileTypeFilter.Add(".db");
return picker.PickSingleFileAsync();
}
I do the same thing when loading a file, I just switch to the PickSaveFileAsync
class instead. As long as I'm saving my database file on the phone/PC, and loading it from there, everything works fine.
If I save the database to OneDrive (as I get OneDrive as one of the options when I run this code on my phone), then download it on my phone using the OneDrive app, and then load the file into the app from the phone storage, it still works perfectly fine.
But, if I save the file on OneDrive, then import it into the app from OneDrive (NOTE: I don't work on the downloaded file, I always copy it into the temp folder and then use that copied file), the database is downloaded and loaded correctly, then the following things happen:
- The database is read fine, but every read operations gets much slower
- Whenever I try to update/insert an item in the database, I get an SQLite ReadOnly Exception
- If I try to overwrite this database file with another database file (like I usually do whenever I want to reset the app database), I get a
NotImplementedException
when I call theStorageFile.CopyAsync
method to actually overwrite the messed up database with a clean database stored in the app Assets folder (I think that this may be caused by the fact that I'm trying to overwrite a database that's flagged as ReadOnly for some reason, but I'm not sure about that, and I don't even know how could it have been marked as ReadOnly in the first place).
I really have no clue on what's going on here, is it my fault or is there something wrong with the SQLite library, or something else?
Thanks!
EDIT: Looks like that the whole downloaded file gets the ReadOnly and Temporary attributes when it gets downloaded from OneDrive, but since that part is handled by the OS itself I'm not sure what should I do here