Solved

read xml elements as string vb.net

Posted on 2013-01-15
4
963 Views
Last Modified: 2013-01-17
So lets say I have a vb.net application written to move files from one path to the other. Now I am tasked with putting the location path in an xml, and loading that data into vb.net so it can be changed on the fly whenever they feel the need to do so.  Im going to be honest this will be my first time using xml in vb.net, and I can use the help.

Also I will need to be able to concatenate other values with the string.

"C:\movePath\" & oRng.Value

Open in new window

Generic example but I hope I am explaining it right.

So to sum it up, I have the file paths located in an xml, I need to read that and put that value into vb.net

Thanks for reading.
0
Comment
Question by:thomashospital
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 38778453
What version of Visual Studio & .Net Framework are you using?
0
 

Author Comment

by:thomashospital
ID: 38778523
VS 2010 and .net 4.0

Sorry should have probably mentioned that.
0
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 250 total points
ID: 38778847
Well, then the easiest way is as following:

Create a class to store your paths:

<System.Serializable()> _
Public Class PathsConfig
    Public Property MiFirstPath As String = String.Empty
    Public Property AnotherPath As String = String.Empty
End Class

In code, you can load and save your paths this way (this code should be in a form, for example):
Imports System.IO

Private _paths As PathsConfig = Nothing

Public Sub LoadPaths()
        Dim voidclass As PathsConfig = new PathsConfig()
        Dim myFileStream As Stream = File.Open(Path.Combine(Application.StartupPath, "paths.xml"), FileMode.Open)
        Dim serializer As New System.Xml.Serialization.XmlSerializer(voidclass.GetType())
        Dim output As Object = serializer.Deserialize(myFileStream)
        myFileStream.Close()

        _paths = output
End Sub

Public Sub SavePaths()
        Dim myFileStream As Stream = File.Create(Path.Combine(Application.StartupPath, "paths.xml")
        Dim serializer As New System.Xml.Serialization.XmlSerializer(_paths.GetType())
        serializer.Serialize(myFileStream, _paths)
        myFileStream.Close()
End Sub

Hope that helps.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 38779425
You can use the AppSettings file (xml file) to store these settings.

http://www.codeproject.com/Articles/12252/Application-settings-in-VB-NET-2-0-and-Visual-Stud
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

856 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