Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Properties.Settings Property doesn't setter any value

I want change value in "MyProject.Properties.Settings.Default.Property" but give to me error and this error;

Severity Code Description Project File Line Suppression State Error CS0200 Property or indexer 'Settings.Version' cannot be assigned to -- it is read only

How I can solve this problem? Or Which I can try different method?

21.03.2017 EDIT - I SOLVED PROBLEM WITH THIS METHOD

Properties.Settings.Default["Version"] = File.GetLastWriteTime(mainDllPath).ToString("ddMMyyyyhhmmss");
Properties.Settings.Default.Save();
like image 538
muratoner Avatar asked Mar 09 '23 13:03

muratoner


1 Answers

From Microsoft:

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.

How To: Write and Persist User Settings at Run Time with C#:

Access the setting and assign it a new value as shown in this example:

Properties.Settings.Default.myColor = Color.AliceBlue;

If you want to persist the changes to the settings between application sessions, call the Save method as shown in this example:

Properties.Settings.Default.Save();

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

You can find more about using settings in c# here.

like image 137
Marcello Avatar answered Mar 24 '23 11:03

Marcello