views:

196

answers:

3

Hi all,

I'm trying to save some XML-Data in my UserSettings (Properties.Settings.Default.UserSettings) in a .NET Winforms Project. Is there a Possibility to do that or would it be better to save this Data in a seperated File?

Thanks for your Answers!

+1  A: 

In a previous project I had a similar idea but decided to keep the xml files separate.

The xml files can be embedded resources, and their file names can be referenced in the Settings file.

I think this is a cleaner solution.

Joe R
+1  A: 

You can store an XML document's string representation in a setting of type String. To save the document, load it into an XmlDocument and set the setting to the value of the XmlDocument.OuterXml property. To retrieve it, create a new XmlDocument and use its LoadXml method to parse the string into an XML document.

This is usually a bad idea. Not because there's anything intrinsically wrong with storing an XML document as text within another XML document -- there isn't. But most settings that you access through the UserSettings property are single values. You're introducing a mode of operation where a single setting can now contain an arbitrary number of actual settings. That's not what most people who read your code are going to expect.

As with a lot of things that give code a bad smell, this may be perfectly fine in your specific implementation. I can imagine circumstances in which I'd do it. But in most cases, I wouldn't.

Robert Rossney
A: 

Thanks for your Answers. As a conclusion, I've decided to extract this stuff into another xml-File which I store in the Resources.

MADMap