Modify appSettings in wen.config file.

Discussion in 'ASP .Net' started by Lubomir, Jul 2, 2008.

  1. Lubomir

    Lubomir Guest

    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
     
    Lubomir, Jul 2, 2008
    #1
    1. Advertising

  2. Lubomir

    bruce barker Guest

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

    -- bruce (sqlwork.com)


    "Lubomir" wrote:

    > 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
     
    bruce barker, Jul 2, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adie
    Replies:
    1
    Views:
    378
    Jon Davis
    Jan 27, 2004
  2. Neelima Godugu

    Modify AppSettings during Install

    Neelima Godugu, May 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,013
    Rick Strahl [MVP]
    May 18, 2004
  3. =?Utf-8?B?U2hhcmsgQmFpdA==?=

    Web.Config file path question "<appSettings file=..."

    =?Utf-8?B?U2hhcmsgQmFpdA==?=, Jun 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    7,802
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Jun 13, 2005
  4. greg
    Replies:
    4
    Views:
    497
    David Segall
    Jan 20, 2006
  5. Stefan Soljemo
    Replies:
    3
    Views:
    762
    Alexey Smirnov
    Nov 4, 2009
Loading...

Share This Page