Solved

Read APP.Configu

Posted on 2013-01-03
2
256 Views
Last Modified: 2013-01-04
Hello

I have the fallown code to read some values from app.config file. When I execute it
I got nothing. What I have wrong. Please, let me now.

I use vb.net 2010.

Thanks you.


Imports System.Configuration

Public Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim name As String = System.Configuration.ConfigurationManager.AppSettings("OperatorName")
        Console.WriteLine("Welcome " + name)

        Dim level As String = System.Configuration.ConfigurationManager.AppSettings("LoggerLevel")
        Console.WriteLine("Logger level: " + level)

    End Sub

End Class

The APP.config file has:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="OperatorName" value="Rita"></add>
    <add key="LoggerLevel" value="5"></add>
  </appSettings>
</configuration>
0
Comment
Question by:jsehernandez
2 Comments
 
LVL 8

Expert Comment

by:5teveo
ID: 38742655
Try this syntax
Assign settings in project...
I assigned a setting named 'S4BackColor'

reference setting using
Me.Groupbox.backcolor = Global.<project name>.My.MySettings.Default.S4BackColor

If my project S4Backcolor variable was encoded as red then my groupbox would be red.
0
 
LVL 8

Accepted Solution

by:
PagodNaUtak earned 500 total points
ID: 38742952
Are you sure that the config you are reading contains the value that you are expecting?

To verify, go to the bin > debug. Inside the debug folder you will see the config file.

Usually, the config file has a naming convention like <project name>.config,

Please let us know the result.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check if number is currency 15 31
Open a word document 23 33
Want to create a userform that looks like the image provided 10 44
Close tabpage of custom control 9 23
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

10 Experts available now in Live!

Get 1:1 Help Now