Jump to content
xisto Community
Sign in to follow this  
tansqrx

.NET XML Configuration File

Recommended Posts

Does anyone know an easy way to create an XML configuration file with Visual Basic.NET? I have a program that I have been working on and I would like to save certain data between sessions. I have heard from many people that XML is the way to go. Are there any good FAQ's

Share this post


Link to post
Share on other sites

Sorry I was away for two days, cudn't reply to this. Usually .NET threads aren't very active here as we have very few .NET coders here. Most people are into C/C++, Java & Scripting. Threads on those topics are likely to move much faster. Anyways, here is your solution.

 

You need to use a DataSet to hold your config options. I'm specifically talking about dataset, coz this control has inbuilt functions called ReadXML and WriteXML - which will read/write the contained data into XML formatted files. If your dataset has two columns - one for the Configuration Option Name and the second one for it's value - that does the job :P

 

Best is to use the following code to create a config file reader/writer class that will handle all your config tasks. Here's how:

Imports System.IO.........Private ConfigFileName as String = "config.ini"Private DSConfig As New DataSet ("Options")............' CODE: For Reading XML config options - best to put it in a separate Sub' Upon Form Load try reading the file - if it exists, populate the dataset with read values,' else simply create a blank dataset with two columns - OptionName and OptionValueIf File.Exists (ConfigFileName) Then    'Read XML and populate    DSConfig.ReadXml (ConfigFileName)Else    'Create blank dataset with two columns    Dim dt As New DataTable ("Values")    dt.Columns.Add("OptionName", System.Type.GetType("System.String"))    dt.Columns.Add("OptionValue", System.Type.GetType("System.String"))    DSConfig.Tables.Add(dt)End If.......' CODE: For Writing out the XML data. Again - best put into a separate subDSConfig.WriteXml (ConfigFileName)....

Hope this helps you get started with it - if you need more code demonstrations or example of a full blown class, post again and I'll guide you to the finalized solution.

 

Regards,

m^e

Share this post


Link to post
Share on other sites

Thanks a million, I'll try it out once I get a chance. Looks like I will have to recruit some VB.NET coder to get in here. This and the exploits section are the only two that I would dare to say I even have a little experience in.Untill then I guess I will just have to post the problems that I am having.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.