I've been programming for a while, not as long as some out there, but for a while. I have programs/code that I've written that has spanned from QBasic to C to Java to, well, you name it really. With each language you gain some things and lose some things. And if you switch platforms, you're definitely getting different libraries, etc... Now that I'm primarily on C#, I have to deal with the lose of a decent built in INI file reader/writer. In C++ (assuming you're on windows), you just call GetPrivateProfileString and I was good to go. In .Net, there's nothing.
It makes perfect sense that there wouldn't be anything in .Net for reading from or writing to an INI file:
-
They want you to use XML (which you should be doing)
-
Use XML already!
But you may run into situations where you need to read an INI file to move over settings. In these instances you're going to have to read it in yourself... Or use this class that I've created... The choice is yours really:
INI.zip (2.07 kb)
I've commented the class. All it really does is parses the file, finding each section, key, and value and holds it in a Dictionary object (which contains the section header and another dictionary containing the key/value pairs). It even writes the file out if you need or puts it into an XML format if you'd like to parse that instead. Anyway, I hope this helps out someone. So give it a try, leave feedback, and happy coding.
347b3631-fa64-4190-98bf-152c956bfcbf|0|.0