Ver Mensaje Individual
  #48 (permalink)  
Antiguo 21/12/2004, 18:12
chcma
 
Fecha de Ingreso: junio-2003
Ubicación: Asturias
Mensajes: 2.429
Antigüedad: 20 años, 10 meses
Puntos: 7
¿Como puedo Leer y Escribir en el AppSettings? (VB y C#)

Bueno, acá os dejo una pequeña clase que he creado:



Imports System
Public Class XMLConfiguracion

Private FicheroConfiguracion As String
Public Sub New(ByVal Fichero As String)
FicheroConfiguracion = Fichero
End Sub

Public Function DevuelveValor(ByVal Llave As String)
Dim FichXml As New Xml.XmlDocument
FichXml.Load(FicheroConfiguracion & ".config")
Dim Child As Xml.XmlNode = FichXml.DocumentElement.SelectSingleNode("/configuration/appSettings/add[@key=""" & Llave & """]")
If Child Is Nothing Then
Return Nothing
Else
Return Child.Attributes("value").Value
End If
End Function

Public Function EstableceValor(ByVal Llave As String, ByVal NuevoValor As String)
Dim FichXml As New Xml.XmlDocument
FichXml.Load(FicheroConfiguracion & ".config")
Dim Child As Xml.XmlElement = CType(FichXml.DocumentElement.SelectSingleNode("/configuration/appSettings/add[@key=""" & Llave & """]"), Xml.XmlElement)

If Child Is Nothing Then
Return False
Else
Child.Attributes("value").Value = NuevoValor
FichXml.Save(FicheroConfiguracion & ".config")
Return True
End If
End Function
End Class
__________________
Charlie.