Ciao a tutti, sto scrivendo una applicazione web in asp.net (vb) e devo leggere dei dati da un file ini. I titoli delle sezioni riesco a leggerli tranquillamente con la funzione:
----
Public Function SezioniIni(ByVal INIFile As String, Optional ByVal bufferSize As Integer = 16384) As String()
Dim sb As New String(" "c, bufferSize)
Dim ret As Integer
ret = GetPrivateProfileSectionNames(sb, sb.Length, INIFile)
Select Case ret
Case 0
Throw New ArgumentException("Invalid INI file.", "INIFile")
Case sb.Length - 2
Throw New ArgumentException("The buffer is too small.", "bufferSize")
End Select
sb = sb.TrimEnd(" "c).TrimEnd(ControlChars.NullChar)
Return sb.Split(ControlChars.NullChar)
End Function
-----
Mentre non riensco a leggere i valori delle chiavi.
Con questa funzione mi solleva una eccezione:
----
Public Function Read(ByVal Filename As String, ByVal Section As String, ByVal Key As String) As String
Dim Result As String
Dim RetVal As String = New String(" ", 255)
Dim LenResult As Integer
Dim ErrString As String
LenResult = GetPrivateProfileString(Section, Key, "non trovato", RetVal, RetVal.Length, Filename)
If LenResult = 0 Then
If Not (File.Exists(Filename)) Then
ErrString = "Impossibile trovare il file " & Filename
Else
ErrString = "Impossibile eseguire l'operazione: la sezione o la chiave sono errate oppure l'accesso al file non è consentito"
End If
Throw New IniException(ErrString)
End If
Result = RetVal.Substring(0, LenResult)
Return Result
End Function
---
Mentre con questa non viene fuori niente:
---
Public Function LeggiIni(ByVal File As String, ByVal Section As String, ByVal Item As String) As String
Dim sBuf As String
Dim iRC As Integer
sBuf = Space(1023)
iRC = GetPrivateProfileString(Section, Item, "Not Found", sBuf, sBuf.Length, File)
sBuf = Left$(sBuf, iRC)
If StrComp(sBuf, "Not Found") = 0 Then
LeggiIni = vbNullString
Else
LeggiIni = Trim(sBuf.ToString)
End If
End Function
-----
per favore aiutatemi, sto impazzendo!!!
![]()
![]()

Rispondi quotando