|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading Application Settings using C# VS 2005In 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 Show quote "Jim Rand" wrote: > 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"]; > > > 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 Show quote "kishor" <kis***@discussions.microsoft.com> wrote in message news:E5B65E8F-3112-42F2-B1AE-EBC782524C51@microsoft.com... > 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" wrote: > >> 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"]; >> >> >> |
|||||||||||||||||||||||