Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the value of appSettings from App.Config file when creating a Windows Service

I am trying to create a Windows Server. I have some logic in C#

        string urlToPing = ConfigurationSettings.AppSettings["UrlToPing"].ToString();         Stream data = client.OpenRead(urlToPing); 

I need to read

Here my App.Config

<?xml version="1.0" encoding="utf-8" ?> <configuration>   <appSettings>     <add key="UrlToPing" value="http://mysite.com"/>   </appSettings>  </configuration> 

I am new at Windows Services, my questions:

  • When I publish to folder the Service or if I create a build I cannot see the App.Config file
    • Visual Studio warning on ConfigurationSettings.AppSettings as obsolete (what should I use instead?)
like image 649
GibboK Avatar asked Jan 31 '13 14:01

GibboK


People also ask

What is the use of AppSettings in web config?

The <appSettings> element stores custom application configuration information, such as database connection strings, file paths, XML Web service URLs, or any other custom configuration information for an application.


1 Answers

To my second question I found a solution:

  1. Add a reference to System.Configuration to your code file.

    using System.Configuration;

  2. The setting may now be referenced correctly...

    ConfigurationManager.AppSettings["UrlToPing"].ToString();

like image 192
GibboK Avatar answered Sep 22 '22 17:09

GibboK