?
Solved

read xml elements as string vb.net

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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using 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.
Suggested Courses

719 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