tags:

views:

50

answers:

3

I want to create an XML file through c# and need to read and write on it.

The data I need to store are just strings and integers.

A: 

Please see Using Settings in C#:

The .NET Framework 2.0 allows you to create and access values that are persisted between application execution sessions. These values are called settings. Settings can represent user preferences, or valuable information the application needs to use. For example, you might create a series of settings that store user preferences for the color scheme of an application. Or you might store the connection string that specifies a database that your application uses. Settings allow you to both persist information that is critical to the application outside of the code, and to create profiles that store the preferences of individual users.

Andrew Hare
+2  A: 

Roughly three options (I shall assume at least .NET 3.5):

  1. Settings as per @Andrew
  2. The built in Serialization tools which work a treat and do some of the heavy lifting for you.
  3. Use Linq to XML (XDocument, XElement, XAttribute etc) which makes it relatively trivial to manually read and write XML in whatever format you require .

To be honest you'll probably achieve the result you want fastest using Linq to XML and its also probably the most flexible approach however you ought to consider what is the most appropriate solution for your particular application - e.g. if the values you're saving are application settings then using the configuration/settings may be more appropriate.

Murph