My ini file was in the windows directory, so I got the path to System32 and
replaced System32 with my filename because Windows is the parent for it.
Dim stmReader As StreamReader = New
FileInfo(System.Environment.SystemDirectory.Replace("System32",
"ditdrn.INI")).OpenText
Dim sINI As String = stmReader.ReadToEnd
This is a different sample but it will give you an idea on how to write
Dim myFileStream As New System.IO.FileStream(sDitPath + "SatPara.dat",
System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write,
System.IO.FileShare.None)
Dim myWriter As New System.IO.StreamWriter(myFileStream)
For i = 0 To sSatPara.GetUpperBound(0)
myWriter.WriteLine(sSatPara(i))
Next
myWriter.Close()
myFileStream.Close()
Ken Simmons
Quote:
> Hi All,
> Is there a simple way in VB.NET to read and write to a .ini file? In old
> VB6 I would use the following, should I just continue with this or has
.NET
> made it easier?
> Thanks,
> Steve
> Private Declare Function GetPrivateProfileString Lib "kernel32" Alias
> "GetPrivateProfileStringA" _
> (ByVal lpApplicationName As String, ByVal lpKeyName As Any, _
> ByVal lpDefault As String, ByVal lpReturnedString As String,
ByVal
> nSize As Long, _
> ByVal lpFileName As String) As Long
> Private Declare Function WritePrivateProfileString Lib "kernel32" Alias
> "WritePrivateProfileStringA" _
> (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal
> lpString As Any, _
> ByVal lpFileName As String) As Long