Solved

How to call web.config file value through window services

Posted on 2008-06-22
2
572 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
2 Comments
 
LVL 18

Expert Comment

by:philipjonathan
Comment Utility
Check this class
System.Configuration.ConfigurationSettings.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 250 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dynamic menu in asp.net c# 11 26
Showdialog 8 20
Jquery autocomplete 10 21
Recommendation vb6 to vb.net or others 14 25
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now