Why are Multiple Locations for .NET Maui programs used for SQLite db storage

Fritz Switzer 261 Reputation points
2023-05-21T14:46:06.2966667+00:00

I am trying to find out the file location for my app's db. Using the same code, the db file is in two different locations for a .NET Maui Windows app.

C:\Users<username>\AppData\Local\

C:\Users<username>\AppData\Local\Packages\CD231D3A-BE0B-45D5-8EBD-7F6DDB6457F8_9zz4h110yvjzm\LocalCache\Local\

Here is the code I am using.

  // TODO Only do this when app first runs
        var assembly = IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly;
        using (Stream stream = assembly.GetManifestResourceStream("MauiApp3.chinook.db"))
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);

                File.WriteAllBytes(EmployeeRepository.DbPath, memoryStream.ToArray());
            }
        }

  private readonly SQLiteConnection _database;

        public static string DbPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "chinook.db");



How do I know where the file will be stored?

I am using an existing db file that is "Embedded Resource" and Copy If Newer

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,179 questions
{count} votes