|
-
November 29th, 2005, 09:47 AM
#1
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# ?
-
November 29th, 2005, 09:56 AM
#2
Re: How do i do ini file in C#.Net ?
Use XML file and take advantage of .NET XML classes for manipulation
"We act as though comfort and luxury were the chief requirements of
life, when all that we need to make us happy is something to be
enthusiastic about."
- Einstein
-
November 29th, 2005, 11:40 AM
#3
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..!
If it helped, then please rate the post by clicking "Rate this post"!
-
November 29th, 2005, 12:25 PM
#4
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
-
November 30th, 2005, 01:48 AM
#5
Re: How do i do ini file in C#.Net ?
-
August 7th, 2006, 09:33 AM
#6
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.
Last edited by efkefk; August 7th, 2006 at 09:35 AM.
-
August 7th, 2006, 10:22 AM
#7
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)
-
August 7th, 2006, 11:20 AM
#8
Re: How do i do ini file in C#.Net ?
" try ... catch" works well.
Thank you.
-
August 8th, 2006, 12:52 AM
#9
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
}
-
August 8th, 2006, 02:45 AM
#10
Re: How do i do ini file in C#.Net ?
Yes, I did that.
This works well.
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|