Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does my C# Config file not load the settings after saving them?

I’m trying to write my Textbox Text into a config file in C# Winfroms to save the text. This is what I have done so far:

The settings:

The code to save the settings:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Properties.Settings.Default.saveToTextBox = saveToTextBox.Text;

The code to load the settings:

saveToTextBox.Text = Properties.Settings.Default.saveToTextBox;

`

And the Events FormClosed and Load to save and load it.

But if I reopen my program the textbox remains empty.

>Solution :

To persist the changes to Settings between application sessions, call the Save method:

Properties.Settings.Default.Save();  

This should work both for .NET Framework 4 and for .NET 6/7.

Settings are saved in a file within a subfolder of the user’s local hidden application data folder.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading