INI files

What is the preferred method of reading and writing Application information to a file and should you keep all of your Application information in the Application.exe.Config file.

I know how to use INI files, but did .NET introduce any methods that are now the preferred method

I have used the application.exe.config file for storing information and have no problems reading data from this file, however I have not found a way to write data to the file.

I am beginning to learn XML, but I have had a hard time finding code examples that demonstrates using an XML Document the same way you would use an INI file.

Any help would be appreciated.


Answer this question

INI files

  • ?®€?§Q?

    you are definitely correct, i've just found a few small times where i've wanted the application to maintain itself, but it barely ever happens
  • Tom Krohn

    The .NET Framework doesn't provide a means of writing to the app.exe.config file for a reason--those settings are meant to be for the assembly itself, not for individual user settings. And yes, XML is probably the simplest solution for storing user settings, although serializing an object that contains all the settings is really easy, too. 

    Where do you put user settings  One solution is to use the Environment.GetFolderPath method to find the location of the users' settings, and store a settings file in that location for each user.

    Another alternative is to use isolated storage, so each application can take care of the details itself, without you needing to worry about exactly where the files go. I just wrote up an article on this stuff for Advisor Publication's VB.NET Journal. If you're interested, send me email and I'll send you an unedited, early PDF version of the article. 


  • buddingb

    you still store all your settings in INI files it's just that now the extension of the file is XML...so yes, we use XML now.  You can either store all your settings in the .config file or you can make up your own schema and put them in a seperate xml file.  Doesn't really matter I don't believe.  You can also create your own configuration readers and make your own schema of settings to be stored in the .config file itself
  • Randy Eppinger

    Oh, of course you're right. I don't really write big apps that use multiple assemblies, but that's another use for it. In any case, I've seen all sorts of people try to make app.exe.config writable, and because you generally don't even have rights to write into files in the folder where it is, I think it's an exercise in futility. Other good options out there! 
  • dcoscio

    That's right, I forgot about IsolatedStorage, my bad...and yes, that's a great one for keeping track of user specific settings.

    You're right about why there's no built in way to write to it (although it's really really easy to make your own), but it's not just there for settings in your Assembly, it's also there for all settings of all Assemblies that are loaded by your main Assembly, such as a Data Layer that stores it's connection there, etc.

  • Shawn.liang

    Thanks for the information, it has definitely cleared some things up.
  • INI files