I created an App.config file in my WPF application:
You have to add the reference to System.configuration
in your solution. Also, include using System.Configuration;
. Once you do that, you'll have access to all the configuration settings.
In your app.config
, change your appsetting to:
<applicationSettings>
<WpfApplication1.Properties.Settings>
<setting name="appsetting" serializeAs="String">
<value>c:\testdata.xml</value>
</setting>
</WpfApplication1.Properties.Settings>
</applicationSettings>
Then, in the code-behind:
string xmlDataDirectory = WpfApplication1.Properties.Settings.Default.appsetting.ToString()
You have to reference System.Configuration
via explorer (not only append using System.Configuration
). Then you can write:
string xmlDataDirectory =
System.Configuration.ConfigurationManager.AppSettings.Get("xmlDataDirectory");
Tested with VS2010 (thanks to www.developpez.net). Hope this helps.
In my case, I followed the steps below.
App.config
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="POCPublishSubscribeQueueName" value="FormatName:Direct=OS:localhost\Private$\POCPublishSubscribe"/>
</appSettings>
</configuration>
Added System.Configuartion
to my project.
Added using System.Configuration
statement in file at top.
Then used this statement:
string queuePath = ConfigurationManager.AppSettings["POCPublishSubscribeQueueName"].ToString();
You can change configuration file schema back to DotNetConfig.xsd
via properties of the app.config
file. To find destination of needed schema, you can search it by name or create a WinForms application, add to project the configuration file and in it's properties, you'll find full path to file.
I have a Class Library WPF Project, and I Use:
'Read Settings
Dim value as string = My.Settings.my_key
value = "new value"
'Write Settings
My.Settings.my_key = value
My.Settings.Save()