Nov 8, 2009

.NET XML Configuration File

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > BASIC / Visual Basic (.NET)

.NET XML Configuration File

tansqrx
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

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
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 smile.gif

Comment/Reply (w/o sign-up)

tansqrx
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?

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
    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 wink.gif

    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:
CODE
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 OptionValue
If 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 sub
DSConfig.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

 

 

 


Comment/Reply (w/o sign-up)

tansqrx
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.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for net, xml, configuration, file
advertisement



.NET XML Configuration File

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com