Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
hleerobinson Valued Contributor.
Valued Contributor.
105 views

Reading settings from the app.config file

Here is something that took me a while to figure out.  I haven't seen any questions about it but I can't be the only one who wants to see the values of the Settings.  I was trying to make sure my app.config transforms were working so I put a menu entry on my form under "Help" to show the values of the application settings.    All of the posts I found kept telling me to use the DefaultValue setting.  Finally, I wised up and first got the name of the setting, then used the name to get the value.  "MNU002" is the name of the program.  Using this, I could check that the transforms put the right values into the Debug, Test, and Release versions of my app.config, depending on the Solution Configuration in effect when I did my Rebuild.

Of course, just using a Setting is as easy as

declare Setting as type MNU002.Properties.Settings
set Setting to new type MNU002.Properties.Settings
move Setting::AOC_ApplicationsServer to ServerName

But I wanted to show a list to the user. 

declare Setting as type MNU002.Properties.Settings
set Setting to new type MNU002.Properties.Settings

move "AppConfig Settings - " & x"0d" & x"0a" to strMsg

perform
       varying SettingsProperty as type System.Configuration.SettingsProperty
    through Setting::Properties

    move strMsg
        &
x"0d" & x"0a"    *> CR LF
      
 & SettingsProperty::Name
          
 to strMsg  
    move strMsg
        &
" = "
       
& Setting::Item(SettingsProperty::Name)
           
to strMsg

end-perform

invoke type MessageBox::Show(strMsg,"MNU002: Show Config Values")

I thought that, at some point, I would like to change the values in app.config and see them immediately in my program, so I found the Reload method:

declare Setting as type MNU002.Properties.Settings
set Setting to new type MNU002.Properties.Settings
invoke Setting::Reload
invoke showConfigValues()

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.