Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# Storing Application Settings

Options
  • 14-07-2010 2:56pm
    #1
    Registered Users Posts: 1,830 ✭✭✭


    I'm attempting to store application settings, however I'm having trouble storing/accessing multiple values.

    E.g I want to store a text list of colours for use in a drop-down box, I've edited my app.config to this;
    <setting name="Colours" serializeAs="String">
    <value>Green</value>
    <value>White</value>
    <value>Gold</value>
    </setting>
    

    But
    Properties.Settings1.Default.Colours
    
    will only contain the 1st value - "Green".

    Any ideas? Or is there an easier way to store application settings with multiple values?


Comments

  • Registered Users Posts: 1,998 ✭✭✭lynchie


    Been a while since I done some .net stuff, but I think you need to serialize your settings as xml and use xml as your value or something along those lines as serializeAs="String" just stores a single value
    <setting name="Colours" serializeAs="XML">
    <value>
    <colorlist>
    <color>Green</color>
    <color>White</color>
    </colorlist>
    </value>
    </setting>
    


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    The problem seems to be that that you have 3 value elements in your setting and you should only have one as you're using serializeAs="string". Have a read of this: http://msdn.microsoft.com/en-us/library/ms229207.aspx which explains the elements. Then you could have a read of: http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx and perhaps roll your own custom settings.

    You may even be able to serialize it as XML and then deserialize the XML as you want it in code.

    <edit>
    lynchie beat me to it
    </edit>


  • Registered Users Posts: 1,830 ✭✭✭CountingCrows


    Muchas gracias!

    I'll test it out in the morning.


Advertisement