Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7493515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:00:30+00:00 2026-05-29T17:00:30+00:00

I have XML-file with settings like this <?xml version=1.0 encoding=utf-8 ?> <configuration> <configSections> <sectionGroup

  • 0

I have XML-file with settings like this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="UpdateReportService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <UpdateReportService.Properties.Settings>
            <setting name="Path" serializeAs="String">
                <value>C:\1</value>
            </setting>
            <setting name="Branch" serializeAs="String">
                <value>200</value>
            </setting>
            <setting name="b204" serializeAs="String">
                <value>192.168.1.55</value>
            </setting>
            <setting name="b200" serializeAs="String">
                <value>192.168.0.83</value>
            </setting>
            <setting name="Hour" serializeAs="String">
                <value>11</value>
            </setting>
        </UpdateReportService.Properties.Settings>
    </applicationSettings>
</configuration>

And I’d like to change some values to values typed by user during install program.

I find example on VB and try convert it to c#:

namespace InstallConfigurator
{
    [RunInstaller(true)]
    public class SettingsClass : Installer
    {
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(Context.Parameters["TARGETDIR"].ToString() + "UpdateReportService.exe");

            ClientSettingsSection applicationSettingsSection = (ClientSettingsSection)config.SectionGroups["applicationSettings"].Sections["UpdateReportService.Properties.Settings"];

            SettingElement Elem = applicationSettingsSection.Settings["Branch"];

            applicationSettingsSection.Settings.Remove(Elem);


            Elem.Value.ValueXml.InnerXml = "30000";
            applicationSettingsSection.Settings.Add(Elem);

            config.Save(ConfigurationSaveMode.Full);
        }
    }
}

But get error “inaccessible due to its protection level” at this place:

SettingElement Elem = applicationSettingsSection.Settings["Branch"];

So, is it possible on c# to access to section in App.config and to change it.


Upd. 2012.02.10

i’ve solved problem this way:

namespace InstallConfigurator
{
    [RunInstaller(true)]
    public class SettingsClass : Installer
    {
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            string xml = Context.Parameters["TARGETDIR"].ToString() + "UpdateReportService.exe.config";

            XmlDocument document = new XmlDocument();
            document.Load(xml);
            XPathNavigator navigator = document.CreateNavigator();
            XmlNamespaceManager ns = new XmlNamespaceManager(navigator.NameTable);

            foreach (XPathNavigator nav in navigator.Select(@"/configuration/applicationSettings/UpdateReportService.Properties.Settings/setting[@name='Branch']/value"))
            {
                nav.SetValue(Context.Parameters["BRANCH"].ToString());
            }

            foreach (XPathNavigator nav in navigator.Select(@"/configuration/applicationSettings/UpdateReportService.Properties.Settings/setting[@name='Path']/value"))
            {
                nav.SetValue(Context.Parameters["PATH"].ToString());
            }

            document.Save(xml);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:00:41+00:00Added an answer on May 29, 2026 at 5:00 pm

    In a similar project, I’m doing it in a slightly different way:

    1. Ship your setup with no “myapp.exe.config” file.
    2. Instead, ship a “myapp.exe.config.default” file that contains placeholders like “{Branch}“.
    3. During setup, load the “myapp.exe.config.default” as a string into memory.
    4. Replace the placeholders with the actual values (e.g. your “30000“).
    5. Write the replaced string as the actual file “myapp.exe.config”.
    6. Bonus: Before writing the config check whether any existing config file is present and copy it as a backup to keep the previous version.

    This runs pretty smooth in our applications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xml file, that looks something like this: <?xml version=1.0 encoding=utf-8?> <Settings>
I have a XML File like that <?xml version=1.0 encoding=utf-8 ?> <Configurations> <EmailConfiguration> <userName>xxxx</userName>
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an xml file like this: <root> <item> <name>one</name> <status>good</status> </item> <item> <name>two</name>
I have the following XML file: <xml version=1.0 encoding=utf-8?> <Data> <Parameter1>1</Parameter1> </Data> I want
I have an XML document in this format: <?xml version=1.0 encoding=utf-8 ?> <SupportedServices> <Service>
Consider this preferences.xml file: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android android:title=@string/preference_main> <PreferenceScreen android:title=@string/preference_sight android:key=category_sight> <ListPreference
I want to make a xml file like: <?xml version=1.0 encoding=Windows-1252 ?> <settings> <typeofsetting>
I have an XML file, which I open in F# like this: let Bookmarks(xmlFile:string)
Say I have an .xml file with a menu that looks like this. <?xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.