Properties.Settings.Default does not work

swodniW 141 Reputation points
2021-07-27T16:16:49.667+00:00

Hello everybody.
In a Windows Forms program i am trying to save a string. Well, the method does not save it.
Please help.

what i've written:
string abc = "abcdefghijklmnopqrs";
Properties.Settings.Default.a_value = abc;
Properties.Settings.Default.Save();
//a_value is a string

Thanks in advance.
bye

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,892 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,917 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,626 Reputation points
    2021-07-28T01:40:29.597+00:00

    Hi VBnetcoder-0336,
    >>the next time you run the program the value is not updated.
    When I run it again, the value I get is "abcdefghijklmnopqrs". I guess what you mean is that the value in the textBox of the value corresponding to "a_value" in the Setting page has not been updated.
    As this document said that Settings that are application-scoped are read-only, and can only be changed at design time or by altering the .config file in between application sessions. Settings that are user-scoped, however, can be written at run time just as you would change any property value.
    The new value persists for the duration of the application session. You can persist the changes to the settings between application sessions by calling the Save method.
    Since design-time tools are not available after the application has been compiled and deployed, you must change the setting value manually in the file.
    Locate the entry for the setting you want to change. It should look similar to the following example(App.config):

    <setting name="a_value" serializeAs="String">  
                    <value>test</value>  
     </setting>  
    

    More details you can refer to this document.
    If I misunderstood what you mean, please explain in detail.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    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.