Solved

Append to xml file

Posted on 2012-04-12
3
308 Views
Last Modified: 2012-04-12
Is there a way to read an XML file and then "append" a line to it with vb code?

Example...on a button click event, could I add this
<add key="strCon" value="user id=lrbrister;pwd=mypassword;data source=lrbrister_dell\;initial catalog=mydatabaser"/>


To this mysettings.config file
<appSettings>
  <add key="KeyToOverride" value="Overridden" />
  <add key="KeyToBeAdded" value="EntirelyNew" />
</appSettings>

So that the file would now look like this
<appSettings>
  <add key="KeyToOverride" value="Overridden" />
  <add key="KeyToBeAdded" value="EntirelyNew" />
  <add key="strCon" value="user id=lrbrister;pwd=mypassword;data source=lrbrister_dell\;initial catalog=mydatabaser"/>
</appSettings>
0
Comment
Question by:lrbrister
3 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 37837644
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 37838451
Try
Dim XReader = XElement.Load(New System.IO.StreamReader("YourXMLFile"))
XReader.Element("appSettings").Add(<add key="strCon" value="user id=lrbrister;pwd=mypassword;data source=lrbrister_dell\;initial catalog=mydatabaser"/>)
XReader.Save("YourXMLFile")

Open in new window

0
 

Author Closing Comment

by:lrbrister
ID: 37838658
Bewst "clean" answer
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

12 Experts available now in Live!

Get 1:1 Help Now