Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INI Files

Status
Not open for further replies.

paullb

Programmer
Jun 27, 2006
5
CZ
I’ll ask you if exist some class for editing and creating ini files in C# ? And how use, because I don’t look for any topic in documentation.

Lot of Thanks

Paul

 
Config versus ini? Seems like pretty much the same thing to me. Both text files with sections and key/value pairs. One happens to include XML tags. I suppose if you need to hide the the info from tampering fingers you can put your ini file anywhere in the system, doesn't have to be in the root dir of the app. On the other hand I don't know if Win32 API will be supported in Vista (haven't isntalled my copy yet). I'm guessing for some period of time it will be.

Code:
dbPath = ConfigurationSettings.AppSettings["DatabasePath"];

dbPath = GetPrivateProfileString("AppSettings",
"DatabasePath", "My.ini");

But it's nice to have choices, go with what works for you.
 
What?

If you don't want an app config file, I would recommend using an xml config file (which you can hide anywhere on the system too!) and it will be a little easier to work with. There's so many tools already available to manipulate xml. XmlTextReader, XmlTextWriter to name a couple.

Unless you are dealing with someone elses ini files in this case.
 
I use NIni, available on SourceForge.

Reasons to use an INI file over a .config or .xml file:

1. Easier for a human to understand, especially if they're not a programmer.
2. Some install packages don't know how to read/write xml-based files, so setting initial values at setup-time is difficult. All setup programs, however, know how to read/write INI files.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
One of the major advantages I've found with .config files is the ability to easily encrypt sections of them. When you do this the Configuration object will automatically decrypt them so that you can read them in using the same method you'd use to read an unencrypted setting. This is especially helpful for things like connection strings, passwords for external software, etc.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
chiph, tnx for the info. Cool util.

The only setback I saw with config files is when I have port some components of my application to C++ or some other language and needs access to config data. Dealing with XML config has been so far, on my experience, a heck of a job.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top