Solved

read xml elements as string vb.net

Posted on 2013-01-15
4
959 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now