Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to call web.config file value through window services

Posted on 2008-06-22
2
Medium Priority
?
584 Views
Last Modified: 2012-08-14
I have created a window services.Now i am looking for to set the timer value , and some reference value in web.config file.And after that i want to call the values in the web.config file through my window service.Can any one have idea abt the windowservices ,sample code is most welcome.
0
Comment
Question by:tanu80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21843915
Check this class
System.Configuration.ConfigurationSettings.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 750 total points
ID: 21844057
To retrieve the configuration information for an arbitrary assembly, use the overloaded constructor or GetConfig method that takes an Assembly reference as input.


Imports System
Imports System.Reflection
Imports System.Collections
Imports System.Xml
Imports System.Configuration
 
' AssemblySettings usage:
' If you know the keys you're after, the following is probably
' the most convenient:
'   VB.NET code
'       Dim settings As AssemblySettings = New AssemblySettings()
'       Dim someSetting1 As String = settings("someKey1")
'       Dim someSetting2 As String = settings("someKey2")
'
 
' If you want to enumerate over the settings (or just as an
' alternative approach), you can do this too:
'       Dim settings As IDictionary = AssemblySettings.GetConfig()
'       Dim entry As DictionaryEntry
'       For Each entry In  settings
'           ' Use entry.Key or entry.Value as desired...
'       Next entry
'
 
' To retrieve the configuration information for an arbitrary assembly,
' use the overloaded constructor or GetConfig method that takes an
' Assembly reference as input.
 
Public Class AssemblySettings
    Private settings As IDictionary
    Public Sub New()
    End Sub
 
    Default Public ReadOnly Property Item(ByVal key As String) As String
        Get
            Dim settingValue As String = Nothing
            If Not (settings Is Nothing) Then
                settingValue = settings(key)
            End If
            If (settingValue Is Nothing) Then
                Return ""
            Else
                Return settingValue
            End If
        End Get
    End Property
 
    Public Overloads Shared Function GetConfig(ByVal configFileName As String) As IDictionary
        ' Open and parse configuration file for specified
        ' assembly, returning collection to caller for future
        ' use outside of this class.
        '
        Try
            Dim cfgFile As String = configFileName 
            Const nodeName As String = "assemblySettings"
 
            Dim doc As New XmlDocument()
            doc.Load(New XmlTextReader(cfgFile))
 
            Dim nodes As XmlNodeList = doc.GetElementsByTagName(nodeName)
            Dim node As XmlNode
            For Each node In nodes
                If node.LocalName = nodeName Then
                    Dim handler As New DictionarySectionHandler()
                    Return CType(handler.Create(Nothing, Nothing, node), IDictionary)
                End If
            Next node
        Catch
        End Try
        Return Nothing
    End Function
End Class

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question