Accessing configuration files programatically CodeSample - XML reading PrivateVersion
From Visual WebGui Wiki
| This article will have a few sections added to it soon, based on the following article type skeleton: NewCodeSampleTemplate |
Overview
This codesample shows how to use generic XML reading of web.config to read whatever value you choose from that file. In this sample we read the PrivateVersion setting.
VB.NET Code
Imports System.IO Imports System.Xml Public Function GetPrivateVersion(ByVal webConfigPath As String) As Integer Dim ret As Integer = 0 'Retrieve the physical path of the web.config file. Dim configXmlDoc As New XmlDocument() configXmlDoc.Load(webConfigPath) ' read the config settings Dim oList As XmlNodeList = configXmlDoc.SelectNodes("configuration/WebGui/PrivateVersion") For i As Integer = 0 To oList.Count - 1 If oList(i).Name = "PrivateVersion" Then Dim oValue As XmlAttribute = oList(i).Attributes("Value") ret = CInt(oValue.Value) End If Next configXmlDoc = Nothing Return ret End Function
C# Code
| The conversion of this code to C# has not been completed yet. Please feel free to contribute and add contents to the Wiki |
