'WinUI 3 Access LocalState Folder

I try to migrate my UWP Application to WinUI3. I use SQLite for persistence and so far the DB file was in the Folder "AppData\Local[Package]\LocalState". But new the file is created under "AppData\Local[Package]\LocalCache\Local". The code to create path is the between both applications:

var databasePath =
    Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
        "moneyfox3.db");

When I look at the path that is generated by that in debug it is something like "C:\user[user]\AppData\Local". So the runtime seems to make a virtual file structure since the app is sandboxed which makes sense. But is there a way to change the path where that virtual file structure is created? Or is there a way to access the LocalState folder so that I can migrate the db file over?



Solution 1:[1]

Windows.Storage.ApplicationData.Current.LocalFolder.Path property should give you the absolute path to the LocalState folder.

As a side note, an MSIX packaged desktop app is not really "sandboxed" but it writes to its own virtual registry and application data folder as explained in the docs here and here.

Solution 2:[2]

Here's the answer. The Environment class contains the location of the local application data that Windows Store applications can use.

// This serializes the account's credentials.
var applicationDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Quarkly