Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading an ini file
Message
From
10/05/2006 10:38:30
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01120658
Message ID:
01120691
Views:
15
>I have to read the contents of an ini file and was wondering if there are any .NET classes to do this. It doesn't have to be anything fancy. I did a quick search and found several interesting sites, but I wanted to get some opinions from UT members before I started looking into this further.

The following is part of my framework:
        Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringW" _
         (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, _
          ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32

        Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
         (ByVal lpApplicationName As String, ByVal lpKeyName As Object, ByVal lpString As Object, _
         ByVal lpFileName As String) As Integer

        ' Read a Main.ini file value
        ' expC1 File
        ' expC2 Section
        ' expC3 Key
        ' expC4 Default value
        '       Optional
        Public Function GetIni(ByVal tcIniPath As String, ByVal tcSectionName As String, _
         ByVal tcKeyName As String, Optional ByVal tcDefaultValue As String = "") As String
            Dim lcData As String
            Dim lnResult As Integer
            Dim lcValue As String
            lcData = Space$(1024)
            lnResult = GetPrivateProfileString(tcSectionName, tcKeyName, tcDefaultValue, lcData, lcData.Length, tcIniPath)
            If lnResult > 0 Then
                lcValue = lcData.Substring(0, lnResult)
            Else
                lcValue = ""
            End If
            Return lcValue
        End Function

        ' Write a Main.ini file value
        ' expC1 File
        ' expC2 Section
        ' expC3 Key
        ' expC4 Value
        Public Sub WriteIni(ByVal tcIniPath As String, _
         ByVal tcSectionName As String, ByVal tcKeyName As String, ByVal tcValue As String)
            WritePrivateProfileString(tcSectionName, tcKeyName, tcValue, tcIniPath)
        End Sub
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform