Permanent MAUI config file survives update of application

Wheelstring 190 Reputation points
2025-01-07T13:19:50.17+00:00

Hello experts

I have a MAUI C# code below, for reading and writing a text file of user setting (like colors, ids, last state..) of MAUI application. Works perfect (development)! (MAUI Android and MAUI Windows)

But what happends with this setting file, if new app version is downloaded from the stores?

Android testings (internal/close) shows, that this settings file is deleted every time when new version of app is downloaded to the mobile from Google Play

How it works (production) on platforms Windows store, Tizen, Apple Store? Android Play store?

Can text file survives update of application?

Thanks a lot

W

        private static string GetSettingsFileName
        {
            get
            {
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Settings.txt");
            }
        }

        public static void WriteSettings(string Content)
        {
            File.WriteAllText(GetSettingsFileName, Content);
        }

        public static string ReadSettings()
        {
            string fName = GetSettingsFileName;
            if (File.Exists(fName))
            {
                return File.ReadAllText(fName);
            }
            else 
                return null;
        }

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,033 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 73,081 Reputation points
    2025-01-07T22:10:02.21+00:00

    your app should not update the application settings file. you should have an additional setting file in the data folder that changes are made to. just add as the last setting file so it overrides the app settings.


1 additional answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 49,611 Reputation points Microsoft External Staff
    2025-01-14T08:24:59.4133333+00:00

    Hello,

    Thanks for your feedback.

    For private data such as user settings, Google provides a solution to back up the required items through the backup function.

    Data backup overview  |  Identity  |  Android Developers mentions the backup of settings.

    Settings data Make sure you also back up and restore settings data to preserve a returning user's personalized preferences on a new device. You can restore settings data even if a user doesn't log in to your app. You can back up settings that a user explicitly sets in your app's UI, as well as transparent data, such as a flag indicating whether a user has seen a setup wizard.

    You could refer to the following documents to learn about the two main methods of implementing backup on the Android platform.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.