Modify appSettings in wen.config file.

  • Thread starter Thread starter Lubomir
  • Start date Start date
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
 
you need to pass the server, site, subpath and a user security token (or
username password) to OpenWebConfiguration.

-- bruce (sqlwork.com)
 
Back
Top