Reading Application Settings using C# VS 2005

  • Thread starter Thread starter Jim Rand
  • Start date Start date
J

Jim Rand

In Properties / Settings, I've got a setting (say "ExportPath") with a value
(say "C:\\Tmp").

Using C#, how do you get the setting value?

string settingValue = SomeNETWhatever["ExportPath"];
 
If you are using visual studio.
add a config file to your solution.
in that file put your entries like this

<configuration>
<appSettings>
<add key="ExportPath" value="C:\\Tmp" />
</appSettings>
</configuration>


and use this


string Exportpath=
CStr(System.Configuration.ConfigurationSettings.AppSettings("ExportPath"))

Bye
Kishor Pise
 
After much time, I've figured it out how to read the application settings
created in the designer:

Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSectionGroup configGroup =
config.SectionGroups["applicationSettings"];
ClientSettingsSection settingsSection = (ClientSettingsSection)
configGroup.Sections["AppSettings.Properties.Settings"];
SettingElementCollection elements = settingsSection.Settings;
foreach (SettingElement element in elements)
{
txtOutput.Text += element.Name + ":" + element.Value.ValueXml.InnerText
+ Environment.NewLine;
}

A simpler approach is just to use the AppSettings that you suggested.

Jim



kishor said:
If you are using visual studio.
add a config file to your solution.
in that file put your entries like this

<configuration>
<appSettings>
<add key="ExportPath" value="C:\\Tmp" />
</appSettings>
</configuration>


and use this


string Exportpath=
CStr(System.Configuration.ConfigurationSettings.AppSettings("ExportPath"))

Bye
Kishor Pise

Jim Rand said:
In Properties / Settings, I've got a setting (say "ExportPath") with a
value
(say "C:\\Tmp").

Using C#, how do you get the setting value?

string settingValue = SomeNETWhatever["ExportPath"];
 
Back
Top