0

I have a C# application where I store certain value in a Settings file like this:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="VITRIconEvacuationPlan.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="VITRIconEvacuationPlan.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <EvacuationPlan.Properties.Settings>
            <setting name="AssemblyCentre" serializeAs="String">
                <value>False</value>
            </setting>
        </EvacuationPlan.Properties.Settings>
    </applicationSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><userSettings>
        <EvacuationPlan.Properties.Settings>
            <setting name="SymbolScale" serializeAs="String">
                <value>25</value>
            </setting>
        </EvacuationPlan.Properties.Settings>
    </userSettings>
</configuration>

Per default, the SymbolScale property is set to 25 (when I start the application the first time) I want to change the SymbolScale property at runtime so I put this into User Scope. So I can say:

setting.SymbolScale = 150;
setting.save();

But when I close my application the value of the SymbolScale is 25 again. But I want it to store my chenged value from the runtime. What am I doing wrong?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Metalhead89
  • 1,740
  • 9
  • 30
  • 58

3 Answers3

2

I found a solution here:

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ddeaca86-a093-4997-82c9-01bc0c630138/

I just had to change and save my SymbolValue like that:

Properties.Settings.Default.SymbolScale = 150;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Save();

I am not sure why I have to call the save function two times but it works (And only with calling it two times)

Metalhead89
  • 1,740
  • 9
  • 30
  • 58
0

Are you sure that you are checking the right "user.config" file? At usual that stored in "C:\Users\xyzuser\AppData\Local\yourcompany\youarpp\version\user.config".

Hope that helps!

mrkurtan
  • 573
  • 2
  • 13
  • I do not have such a config file. I just wrote an assembly which I use as a plugin in AutoCAD. I just created the app.config via the Visual Studio Settings Property. (Project -> Properties -> Settings -> Settings.settings) – Metalhead89 Dec 29 '12 at 18:38
0

Set it like: Settings.Default.SymbolScale = 150;

Save it with Settings.Default.Save();

VladL
  • 12,769
  • 10
  • 63
  • 83
  • I have changed it to application scope but When I try to change the value it tells me that it is write-protected. – Metalhead89 Dec 29 '12 at 18:36
  • 1
    @Metalhead89 you were right, I've edited my answer. Does it work this way for you? It worked for me as user scope setting – VladL Dec 29 '12 at 18:46