Home All Groups Group Topic Archive Search About

How do i read and write ini file using vb.net?

Author
21 Dec 2006 5:09 PM
TBoon
How do i read and write ini file using vb.net?

Author
21 Dec 2006 5:10 PM
Herfried K. Wagner [MVP]
"TBoon" <allblack***@hotmail.com> schrieb:
> How do i read and write ini file using vb.net?

Storing and loading user preferences
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=userpreferences&lang=en>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
21 Dec 2006 5:40 PM
vbnetdev
xml is a better way to go in my humble opinion.

http://www.kjmsolutions.com/xmlsettings.htm

Show quoteHide quote
"TBoon" <allblack***@hotmail.com> wrote in message
news:OKbPIJSJHHA.3552@TK2MSFTNGP03.phx.gbl...
> How do i read and write ini file using vb.net?
>
Author
22 Dec 2006 7:51 PM
Jeff Jarrell
If you are looking for the legacy approach... (pinvoke.net is a nice site
for finding these sorts of things).

Class Util
  Public Shared Function readINI(ByVal sSection As String, ByVal sKey As
String, ByVal sFile As String) As String
   Dim sb As StringBuilder
   Dim iRet As Integer

   sb = New StringBuilder(500)

   iRet = WinApi.GetPrivateProfileString(sSection, sKey, "", sb,
sb.Capacity, sFile)

   Return sb.ToString
  End Function

  Public Shared Sub writeINI(ByVal sSection As String, ByVal sKey As String,
ByVal sFile As String, ByVal sValue As String)
   Dim bOk As Boolean

   bOk = WinApi.WritePrivateProfileString(sSection, sKey, sValue, sFile)
  End Sub
end class




Class WinApi
  <DllImport("kernel32.dll", SetLastError:=True)> _
  Public Shared Function GetPrivateProfileString(ByVal lpAppName As String,
_
   ByVal lpKeyName As String, _
   ByVal lpDefault As String, _
   ByVal lpReturnedString As StringBuilder, _
   ByVal nSize As Integer, _
   ByVal lpFileName As String) As Integer
  End Function

  <DllImport("kernel32.dll", SetLastError:=True)> _
  Public Shared Function WritePrivateProfileString(ByVal lpAppName As
String, _
   ByVal lpKeyName As String, _
   ByVal lpString As String, _
   ByVal lpFileName As String) As Boolean
  End Function
End Class


Show quoteHide quote
"TBoon" <allblack***@hotmail.com> wrote in message
news:OKbPIJSJHHA.3552@TK2MSFTNGP03.phx.gbl...
> How do i read and write ini file using vb.net?
>