Reputation: 7207
I am using VS2015, C#.
I've created a couple of settings via project properties - settings. Some of them are saved here:
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Calendar.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Calendar.Properties.Settings>
<setting name="RedirectUriDEBUG" serializeAs="String">
<value>https://localhost:44367/Login/RedirectGoogle</value>
</setting>
<setting name="RedirectUriPRODUKCIJA" serializeAs="String">
<value>https://ztest30.franjobrekalo.com/Login/RedirectGoogle</value>
</setting>
<setting name="LogPathDEBUG" serializeAs="String">
<value>C:\Users\Frenky\Desktop\AdministrationLog.txt</value>
</setting>
<setting name="LogPathPRODUKCIJA" serializeAs="String">
<value>h:\root\home\frenkyb-001\www\administration\AdministrationLog.txt</value>
</setting>
<setting name="LogPathTEST" serializeAs="String">
<value>h:\root\home\frenkyb-001\www\testnotes\AdministrationLog.txt</value>
</setting>
</Calendar.Properties.Settings>
</applicationSettings>
ApplicationSettings section was generated by visual studio. Now I need to read from applicationSettings. I've tried numerous solutions, to my surprise, nothing worked. It seems that reading from appSettings is easy or from connectionStrings. Why is the problem with generated applicationSettings section?
EDIT:
Problem is with applicationSettings not with appSettings.
Upvotes: 1
Views: 4862
Reputation: 799
For me, The answer was in this article: https://www.c-sharpcorner.com/article/four-ways-to-read-configuration-setting-in-c-sharp/
It shows how to use ConfigurationManager.GetSection
method to get a NameValueCollection
from applicationSettings
Example with custom section could be:
NameValueCollection PostSetting = ConfigurationManager.GetSection("BlogGroup/PostSetting") as NameValueCollection;
And with the default ApplicationSettings
section:
NameValueCollection applicationSettings = ConfigurationManager.GetSection("ApplicationSettings") as NameValueCollection;
Upvotes: 0
Reputation: 1
Look for the KEY 'RedirectUriDEBUG' in all your project code... and Visual Studio will find a reference...
It should be somtething like
global::[YOUR_PACKAGE_NAMESPACE].Properties.Settings.Default.[YOUR_KEY] Hope it helps
Upvotes: 0
Reputation: 119
You can use ConfigurationManager
class.
Try: ConfigurationManager.AppSettings
. For detailed info check out msdn.
EDIT: Check out this link once. It seems you cannot use inbuilt API's for ApplicationSettings. It only works for appSettings and connectionStrings. For your case you need to implement a custom class as explained in the above link.
Upvotes: 2