Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

read xml elements as string vb.net

Posted on 2013-01-15
4
Medium Priority
?
979 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

972 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