read/write an .ini file 
Author Message
 read/write an .ini file

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



Tue, 24 May 2005 18:24:37 GMT  
 read/write an .ini file
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



Wed, 25 May 2005 03:27:16 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Reading / Writing an INI file

2. Reading / Writing an INI file

3. How to Read/Write to INI FIle

4. Read/Write to INI files in VB5

5. Read/Write to INI files in VB5???

6. How to read/write to ini file on a network?

7. Read/Write INI Files w/Access 7.0

8. Ini-file, read write and empty lines.

9. Reading and writing from and to ini files

10. Reading and writing to an INI file?

11. Reading and Writing to .ini files - help please.

12. Read and Write to INI files

 

 
Powered by phpBB® Forum Software