How do i do ini file in C#.Net ?
in Visual C++ i had :
Set/GetPrivateProfileString , GetPrivateProfileint and more , creating a file with a label and a tag for each variable like :
[House]
chairs=5
doors=7
[City]
hospitals=2
airport=1.
Is there a better way to save values of variables when the application is closed and get them when the application starts ?
and if not , how do i make an ini file in C# ?
Re: How do i do ini file in C#.Net ?
Use XML file and take advantage of .NET XML classes for manipulation
Re: How do i do ini file in C#.Net ?
Yeah, should use XML where you can.
Pretty sure this is a link to a nice library that allows XML, INI, Registry etc editing (Couldn't confirm the link, the site is playing up..!)
http://www.codeproject.com/csharp/ReadWriteXmlIni.asp
Tidy bit of code..!
Re: How do i do ini file in C#.Net ?
I used Nini library (its free with source code), and really enjoyed it:
http://nini.sourceforge.net/
Here is an example of usage:
http://nini.sourceforge.net/manual.php#ASimpleExample
Re: How do i do ini file in C#.Net ?
Re: How do i do ini file in C#.Net ?
Hello,
I am trying to use nini for ini files. Just one problem:
When trying to read non existing section/key, there is this error message "NullReferenceException was unhandled".
Do you know how to proceed to avoid this ?
Regards.
Re: How do i do ini file in C#.Net ?
Put try...catch surrounding the problematic code.
Or you could try to fix the bug (it's an open source with full source code)
Re: How do i do ini file in C#.Net ?
" try ... catch" works well.
Thank you.
Re: How do i do ini file in C#.Net ?
Why don't you catch the exception and do what you want with it ( could do nothing if you like) ?
try
{
// read and unexisting section - that will throw an exception
}
catch (Exception) // catch any exception thrown
{
// do something or nothing
}
Re: How do i do ini file in C#.Net ?
Yes, I did that.
This works well.
Thank you.