none
How can I keep the setting while program moved? RRS feed

  • Question

  • I used a Setting.settings to store the program setting and I found that whenever I move the program file to another directory in  the same computer, all the setting will lost.

    I wonder if there is a way to keep the setting no matter I move it to anywhere. Thank you.

    Monday, July 1, 2019 2:01 AM

Answers

  • Reproduced the behaviour when changing a setting by code (See here):

                Properties.Settings.Default.MySetting = "Hello";
                Properties.Settings.Default.Save();

    When doing so, a config file is saved under %AppData%\Local\MyAppName\MyAppName.exe_Url_[some random stuff here] and when the exe gets moved, a new folder is created here (assuming representing the exe's location).

    So you probably better use a config file instead of the settings file. In this case, the config file must also be copied.


    Wednesday, July 3, 2019 8:41 AM

All replies

  • Hello,

    The default location is under 

    C:\Users\UserName\AppData\Local\Microsoft

    And when placing the app in a different location the settings are stored in a different folder than the prior app.

    To remedy this you need to store data in a roaming folder,

    https://docs.microsoft.com/en-us/uwp/api/Windows.Storage.ApplicationData#Windows_Storage_ApplicationData_RoamingSettings

    see the following blog post.

    https://blogs.windows.com/windowsdeveloper/2016/05/03/getting-started-with-roaming-app-data/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, July 1, 2019 2:41 AM
    Moderator
  • Hello,

    The default location is under 

    C:\Users\UserName\AppData\Local\Microsoft

    And when placing the app in a different location the settings are stored in a different folder than the prior app.

    To remedy this you need to store data in a roaming folder,

    https://docs.microsoft.com/en-us/uwp/api/Windows.Storage.ApplicationData#Windows_Storage_ApplicationData_RoamingSettings

    see the following blog post.

    https://blogs.windows.com/windowsdeveloper/2016/05/03/getting-started-with-roaming-app-data/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    The way you provided is about UWP, but now I am using the Winform&&WPF. It seems much more different from the UWP yet.
    Monday, July 1, 2019 3:23 AM
  • Try signing the assembly in Signing tab of Project Properties. For example, choose a new .snk file without a password. Then rebuild the project.

    Monday, July 1, 2019 5:39 AM
  • Hi mywatermelon,

    Thank you for posting here.

    Based on my test, I could not reproduce your problem even if I move the program.

    Code:

      private void Button1_Click(object sender, EventArgs e)
            {
                int a = Properties.Settings.Default.Id;
                MessageBox.Show(a.ToString());
            }

    Result:

    You also could download it to check it.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 1, 2019 8:19 AM
    Moderator
  • Hi mywatermelon,

    Thank you for posting here.

    Based on my test, I could not reproduce your problem even if I move the program.

    Code:

      private void Button1_Click(object sender, EventArgs e)
            {
                int a = Properties.Settings.Default.Id;
                MessageBox.Show(a.ToString());
            }

    Result:

    You also could download it to check it.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    No, not moving the window, but moving the whole program file which was published to another directory. Just placing the app in a different location as what @Kareninstructor said.
    Tuesday, July 2, 2019 10:00 AM
  • Hi mywatermelon,

    Thanks for the feedback.

    I re-do a test, I still could not reproduce your problem. could you provide an image about your problem?

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 3, 2019 7:24 AM
    Moderator
  • Reproduced the behaviour when changing a setting by code (See here):

                Properties.Settings.Default.MySetting = "Hello";
                Properties.Settings.Default.Save();

    When doing so, a config file is saved under %AppData%\Local\MyAppName\MyAppName.exe_Url_[some random stuff here] and when the exe gets moved, a new folder is created here (assuming representing the exe's location).

    So you probably better use a config file instead of the settings file. In this case, the config file must also be copied.


    Wednesday, July 3, 2019 8:41 AM