AppSetting in C# in WinForm App

I'm doing something stupid, but can't see it.

Trying to read a configuration value out of app settings. File is:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
      <configSections>
  <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
   <section name="CSharpPushKDX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </sectionGroup>
 </configSections>
 <applicationSettings>
  <CSharpPushKDX.Properties.Settings>
   <setting name="LogFilePath" serializeAs="String">
    <value>C:\Saros\SarosNet35\PushKDX\PushKDX\PushKDX%d%.log</value>
   </setting>
  </CSharpPushKDX.Properties.Settings>
 </applicationSettings>
</configuration>

Code is:

            string lsAnswer = "";
            try
            {
                lsAnswer = System.Configuration.ConfigurationManager.AppSettings.Get("LogFilePath");
                lsAnswer = System.Configuration.ConfigurationManager.AppSettings["LogFilePath"];
                lsAnswer = ConfigurationSettings.AppSettings["LogFilePath"];
            }
            catch
            {
                lsAnswer = "";
            }

Note that I have tried to get the desired value three different ways. All return null.

I'm trying to switch over from VB.NET to c# with this project, so I expect some dumb translation issue.

Thanks...
LVL 1
kwebster7327Asked:
Who is Participating?
 
microboltConnect With a Mentor Commented:
Make sure there there are no namespace issues. The fully qualified name of the Resources class would be YourProject.Properties.Resources, so if something has caused the Form to be placed in a different namespace from your Properties class, you would need to use the fully qualified name to access it from the form. Use the Object Browser to browse your solution and figure out what the namespace of your Properties class is.
0
 
eirikurhCommented:
try
string lsAnswer = Properties.Settings.Default.LogFilePath
0
 
microboltCommented:
Try it like this:

lsAnswer = Properties.Settings.Default.LogFilePath
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
kwebster7327Author Commented:
The name 'Properties' does not exist in the current context.
0
 
kwebster7327Author Commented:
Close! If I move it back into the main namespace, it. works.

I'm trying to make this part of a general-purpose, reusable function, so I guess I'll need to figure out how to pass the namespace name into it?

Also, this references the default value of the parameter. If the value gets changed after deployment, will that new value get picked up or will we always get the default?

Thanks...
0
 
microboltCommented:
You can just Import the main namespace at the top of your file and it should work as well.  Then when you use it in multiple projects just change the Import at the top.
0
 
kwebster7327Author Commented:
Assume you me "using" instead of "imports" - this is C#.

0
 
microboltCommented:
Yep, had an brain fart =D
0
All Courses

From novice to tech pro — start learning today.