Best format for configuration file?

  • Thread starter Joe Mayo [C# MVP]
  • Start date
J

Joe Mayo [C# MVP]

Jimbo said:
What's the best format to save a configuration file?
I'm currently using an INI extension and I write it like a normal ascii
file. Is this the best way? I've heard of using XML to create a config file.
What would be the best format?


Hi Jimbo,

I recommend XML. Look for configuration file information in the docs. In
VS.NET, you can add a file named "app.config" to your application and work
with it in the IDE. When you compile, this file will be copied to your
output directory, where your dll is, and be renamed to <put your application
name here>.exe.config.

Joe
 
A

Antenna

A .NET app can have a config file with the extension ".config". Suppose
your app is named "myapp.exe", then your config file must be named
"myapp.exe.config".

A simple config file looks like this:

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="name1" value="value1" />
<add key="name2" value="value2" />
</appSettings>
</configuration>

Use System.Configuration.ConfigurationSettings to manipulate it.
 
R

Roman S. Golubin

Hello Jimbo!
What's the best format to save a configuration file?
I'm currently using an INI extension and I write it like a normal ascii
file. Is this the best way? I've heard of using XML to create a config file.
What would be the best format?

The XML is good format for configuration files (IMO). And the XML
Serialization process is very simple to save and read XML files into objects
tree.
 
J

Jimbo

What's the best format to save a configuration file?
I'm currently using an INI extension and I write it like a normal ascii
file. Is this the best way? I've heard of using XML to create a config file.
What would be the best format?

Thank you.
 
G

gabriel

Jimbo said:
What's the best format to save a configuration file?
I'm currently using an INI extension and I write it like a normal
ascii file. Is this the best way? I've heard of using XML to create a
config file. What would be the best format?

I'll risk being ridiculed, but INI files work perfect for me. The thing
about XML is that if you edit by hand you can corrupt really easily,
specially if someone unfamiliar with XML does it.

INI files are soooo straightforward and simple that it's much harder to
screw them up.
 
B

bob holder

gabriel said:
I'll risk being ridiculed, but INI files work perfect for me. The thing
about XML is that if you edit by hand you can corrupt really easily,
specially if someone unfamiliar with XML does it.

INI files are soooo straightforward and simple that it's much harder to
screw them up.

No ridicule from this end. Actually, ascii based ini files fit very well
into the .NET xcopy deployment scheme. Having your users become human xml
parsers is no fun.

bob
 
C

Cezary Nolewajka

If you want to write to the config file from your application you cannot use
the app.config file.

I reckon the best and most flexible solution is XML Serialization. Moreover,
it has advantages towards flat <appSettings> element and it's subelements.

Using XML Serialization you can desing your own class with all application
settings you need and simply serialize/deserialize it into/from a file.

You gain read/write settings capabilities and more complex settings
structure including even arrays and nested elements.

You can go as far as:
<Settings>
<Section1>
<OptionName value="123" output="098324-2" />
<OptionName value="kljewr" output="098324-2" />
<OptionName value="-93mc[" output="098324-2" />
<OptionName value="[apioewcr" output="098324-2" />
</Section1>
<Section2>
<OptionName value="123" output="098324-2" />
<OptionName value="kljewr" output="098324-2" />
<OptionName value="-93mc[" output="098324-2" />
<OptionName value="[apioewcr" output="098324-2" />
</Section2>
...
</Settings>
 
U

UAError

Jimbo said:
What's the best format to save a configuration file?
I'm currently using an INI extension and I write it like a normal ascii
file. Is this the best way? I've heard of using XML to create a config file.
What would be the best format?

Thank you.

For an example of managing a custom XML application configuration file look under

Working with Custom Application Files in C#

on

Visual C# .NET Code Samples
http://www.microsoft.com/downloads/...eb-7152-454d-9936-495ffd79afd0&displaylang=en
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top