Solved

read xml elements as string vb.net

Posted on 2013-01-15
4
966 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

OfficeMate Freezes on login or does not load after login credentials are input.
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
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.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

734 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