tansqrx 0 Report post Posted April 25, 2005 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
miCRoSCoPiC^eaRthLinG 0 Report post Posted April 26, 2005 I do. I've been working on it for quite sometime now. Check during later part of today - I'll have some sample code for you. Extremely busy right now, sorry Share this post Link to post Share on other sites
tansqrx 0 Report post Posted April 28, 2005 Thanks, I've tried to google it but all I get is ASP related XML. BTW this isn't a very active thread it it? Share this post Link to post Share on other sites
miCRoSCoPiC^eaRthLinG 0 Report post Posted April 28, 2005 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 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
tansqrx 0 Report post Posted April 28, 2005 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