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!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.