Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / February 2007

Tip: Looking for answers? Try searching our database.

Merging two configuration files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Houda - 27 Feb 2007 21:08 GMT
Here what I've been trying to do:
I've two different configuration files with the same structure. One of
them is the default setting, which gets downloaded from the server,
and the other one is the user settings. The user settings overwrite
the default settings. Similar to what .Net does with the
machine.config file and the web.config. Now I need to merge these two
files to get the actual settings.

The default settings file:

<bookmarks>
     <add name="b1" lat="1" long="1"/>
     <add name="b2" lat="1" long="1"/>
     <add name="b3" lat="1" long="1"/>
<bookmarks/>

The user settings file:

<bookmarks>
     <remove name="b1" lat="1" long="1"/>
     <add name="b4" lat="1" long="1"/>
<bookmarks/>

The result after merging these two files should be:

<bookmarks>
     <add name="b2" lat="1" long="1"/>
     <add name="b3" lat="1" long="1"/>
     <add name="b4" lat="1" long="1"/>
<bookmarks/>

Any ideas how to do this? If you think I should post this message to
another group let me know?

Thanks
Houda
Jani Järvinen [MVP] - 28 Feb 2007 14:59 GMT
Hi Houda,

> The user settings overwrite
> the default settings. Similar to what .Net does with the
> machine.config file and the web.config. Now I need to merge these two
> files to get the actual settings.

There's nothing automatic in .NET for this, so your best bet is to first
read the default settings into memory (into some kind of collection object
perhaps), and then read the user settings.

If you use the "name" attribute as a key, then for each line you load from
the user's settings, check to see if a setting with a similar name already
exists in your collection, and then act accordingly.

In the end, you have effectively merged the two XML files. Then, you can
process the collection's data or write the data out as a new XML file, if
that is what you want to do.

Hope this helps.

Signature

Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
janij@removethis.dystopia.fi
http://www.saunalahti.fi/janij/

Houda - 28 Feb 2007 18:57 GMT
It seems there is a way to do this. Take a look at this one:

http://72.14.253.104/search?q=cache:RqMrrtmqM_0J:https://forums.microsoft.com/MS
DN/ShowPost.aspx%3FPostID%3D671699%26SiteID%3D1+ExeConfigurationFileMap+MachineC
onfigFilename+merging&hl=en&ct=clnk&cd=5&gl=us


Houda

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.