Is there anything in .NET v1.1 for reading/writing my own INI files?

  • Thread starter Thread starter Rob R. Ainscough
  • Start date Start date
R

Rob R. Ainscough

I use my own application INI files that do NOT reside in the registry.

GetPrivateProfileString("Options"..."MyFile.INI")
WritePrivateProfileString ("Options"..."MyFile.INI")

I'm trying to remained "managed" and was looking at
Microsoft.Win32.Registry, but that isn't flexible enough to deal with user
defined INI files. Is there any other managed option?

Thanks, Rob.
 
In .NET we seem to have moved to .config files based on xml rather than the
..ini format. You can still use the win32 stuff for ini though. I would take a
look into the .config method or serialize your own object (wich is what I do)
 
William,

I need to read the INI of another application -- basically I read the
Registry to locate where the other application is installed (not a .NET
based app), then the application has it's own "old fashion" INI file that I
need to read to discover other values/settings. XML has a little more
overhead than I need, but I'll certainly use System.Xml for any application
specific work I do for my .NET managed apps.

I've basically ended up writing my own INI class using the
System.IO.FileStream.

Rob.
 
Hi Rob,

If you want to use ini files, you would find interesting the Nini project.
Within Nini, you can read severla types of config files, including INIs. The
INI reader has been developed as a managed component, with no Windows API, so
it´s cross platform (and safe)

You can get Nini at http://nini.sourceforge.net/

Regards,
Leon
 
I call the Win32 API (this is C#):

[DllImport ( "kernel32" , SetLastError=true ,
EntryPoint="GetPrivateProfileString" )]
private unsafe static extern uint
API_GetPrivateProfileString
(
string lpAppName ,
string lpKeyName ,
string lpDefault ,
byte* lpReturnedString ,
int nSize ,
string lpFileName
) ;

public unsafe static int
GetPrivateProfileString
(
string lpAppName ,
string lpKeyName ,
string lpDefault ,
out string lpReturnedString ,
int nSize ,
string lpFileName
)
{
int result ;
byte[] temp = new byte [ nSize ] ;

fixed ( byte* ptemp = temp )
{
result = (int) API_GetPrivateProfileString
(
lpAppName ,
lpKeyName ,
lpDefault ,
ptemp ,
nSize ,
lpFileName
) ;
}

lpReturnedString = PIEBALD.Lib.LibStr.FromByteArray ( temp ,
true ).Substring ( 0 , result ) ;

return ( result ) ;
}
 
Back
Top