Modify appSettings in wen.config file.


L

Lubomir

Hi,

I have a custom settings in <appSettings> section in the web.config. I need
to modify this section from the C# exe application (NOT asp.net)

web.config:
<appSettings>
<add key="MyKeyName" value="MyValue"/>
<appSettings/>

I am using the following code:

System.Configuration.Configuration configuration =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(
"/MyWebSite/MyApp" );
System.Configuration.AppSettingsSection app =
(System.Configuration.AppSettingsSection)configuration.GetSection(
"appSettings" );
app.Settings["MyKeyName"].Value = value;


1/
The collection app.Settings is empty; should contain one item.

2/
Also I am not sure if the path "/MyWebSite/MyApp" is in correct format, as
there is expected the virtual path = how to find what is the virtual path for
web.config in MyApp application folder? I wouldlike to note again, this code
is an *.exe C# application, not asp.net.

Any help would be appretiated.

Thanks,
Lubomir
 
Ad

Advertisements

B

bruce barker

you need to pass the server, site, subpath and a user security token (or
username password) to OpenWebConfiguration.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top