modify app.config file

Posted on 2012-09-07
Last Modified: 2012-10-05
Hi Guys,

I am working on a project where I need to build 30 machines with a specific application.

The app.config file references the machine name (developers have been lazy and not done waht we want and have this auto populate with system.environment.machinename which is being addresses)

instead I need to populate this in the app.config file along with a few other lines.

my current app.config file looks like this

<?xml version="1.0" encoding="utf-8"?>
        <add key="DeviceName" value="panasoncic cf-h2" />
    <add key="ServerName" value="" />
    <add key="Username" value="222" />
    <add key="Password" value="111" />
    <add key="DeleteAfterSend" value="N" />
    <add key="ApproveBeforeSend" value="N" />
    <add key="AutoApprove" value="N" />
    <add key="UseSSL" value="Y" />
    <add key="AutoSync" value="Y" />
    <add key="SyncOccurances" value="-1" />
    <add key="PurgeDays" value="-1" />
    <add key="RequireLogon" value="N" />
    <add key="PrinterPort" value="" />
    <add key="PrinterBTPort" value="" />
    <add key="GPSPort" value="" />
    <add key="GPSBaudRate" value="9600" />

Open in new window

i need to modify the username, password, url and device name..... and will then deploy the app.config file to the specified machine.

ive been looking on here but cant find an asnwer that is a complete or makes sense..

I have been able to read the values easily, but am struggling to write as this is new teritory for me.

any and all help will be very much appreciated.


Question by:SimonPrice33
    LVL 55

    Accepted Solution

    Hi, how are you reading the config file?
    There is not an easy way to modify an xml, as far as I know. You have to rewrite it entirely.

    Author Comment

    Hi i have imported system.configuration.confurationsettings

    Then have a a text field called txtmachine

    Txtmachinename.text  = appsettings("devicename")

    Which readsit....

     Iwas thinking this morning that i would ave to rewrite the entire config again but as its simply just xml will write it with linq

    Ill let you knownhowni get on
    LVL 83

    Expert Comment

    What happens if you try

    appsettings("devicename") = Txtmachinename.text


    Author Comment

    sorry... didnt see this comment...

    i will test and come back to you... thats on a different machine to what im on at the moment

    Author Comment

    the modification of the config file crashes the application...  the deadline on this project has passed and i had to work it manually...

     thanks for your help guys

    Author Closing Comment


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now