3 Replies - 343 Views - Last Post: 10 April 2013 - 08:01 AM Rate Topic: -----

#1 wtfnix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-April 09

Trying to pull from a xml file after user selects one

Posted 10 April 2013 - 03:53 AM

I've been looking around for resources on the following code that I been starting on which I'm new to vb.net and found I like the language overall however the code is where I'm stumped is how to pull from the xml file within the textbox control after the user selects this:

(Thanks in advance for the pointer(s)) :bigsmile:/>/>

1. User searches for the .xml file

2. User clicks Export (THIS IS WHERE I'm stumped)

How do I invoke or pull from the C:\Users\username\Desktop\userxmlfile.xml that's within the textbox control once the user selects the file? I can't seem to find anything on the net or the proper terms for it? How to tell btnExport to open the file that's in the textcontrol.

(I'll try to figure this out, but a pointer on whatever is best to use to read XML files would be appreciated.) Then I can start using Streamreader and Regex to pull out a certain "NODE" of the XML file.


3. After this is preformed it should populate the ListBox control

4. Then the user can click to save this to a .txt file as a list.

I'm not looking for a full working concept of this, I want the challenge on completing this by myself, but I'm sorta lost on how and what to look for here... Since .net seems so huge.

Here's the code that I have so far, however I can't seem to find any information on when I press btnExport_Click, I need to have it select what's in the txtFile control:


Public Class frmMainExtractor

    Property Filter As String

    Private Sub btnFindFile_Click(sender As Object, e As EventArgs) Handles btnFindFile.Click
        OpenFileDialog1.Title = "Please select your XML file..."
        OpenFileDialog1.InitialDirectory = "C:temp"

        OpenFileDialog1.ShowDialog()

    End Sub

    Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

        Dim strm As System.IO.Stream
        strm = OpenFileDialog1.OpenFile()
        txtFile.Text = OpenFileDialog1.FileName.ToString()
        If Not (strm Is Nothing) Then
            strm.Close()
            MessageBox.Show("File Successfully Selected.")
        End If
    End Sub

    Private Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click

        ' Node in XML to search for: <Combo>Ctrl+Alt+3</Combo> which uses the Combo so a regex is needed between the Combo node more than likely.


    End Sub
End Class




Here's an image of the layout for the visual ones on where I'm stumped if you need:

Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to pull from a xml file after user selects one

#2 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: Trying to pull from a xml file after user selects one

Posted 10 April 2013 - 06:19 AM

Try importing the System.XML namespace; this contains everything you'll need for interacting with .xml in VB.net.
Was This Post Helpful? 0
  • +
  • -

#3 wtfnix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-April 09

Re: Trying to pull from a xml file after user selects one

Posted 10 April 2013 - 06:47 AM

View PostC.Andrews, on 10 April 2013 - 06:19 AM, said:

Try importing the System.XML namespace; this contains everything you'll need for interacting with .xml in VB.net.


Right but my question is mainly:

Once you have the file selected, how / what is the proper way to call this file from the textbox control that you selected?
Was This Post Helpful? 0
  • +
  • -

#4 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: Trying to pull from a xml file after user selects one

Posted 10 April 2013 - 08:01 AM

View Postwtfnix, on 10 April 2013 - 01:47 PM, said:

View PostC.Andrews, on 10 April 2013 - 06:19 AM, said:

Try importing the System.XML namespace; this contains everything you'll need for interacting with .xml in VB.net.


Right but my question is mainly:

Once you have the file selected, how / what is the proper way to call this file from the textbox control that you selected?


Well, when I'm working with lists of files, what I do is use the DirectoryInfo and FileInfo types to populate my lists and manipulate the files as needed. Here's an example where I'm populating a listbox with files for the user to select:

 Dim dir As New IO.DirectoryInfo(Application.StartUpPath)
            Dim aryFi As IO.FileInfo() = dir.GetFiles("*.dir")
            Dim fi As IO.FileInfo
            For Each fi In aryFi
                lstAvailable.Items.Add(fi.Name)
            Next



Once the first list box has been populated with available files, I can select items from it and move them into another listbox; then, when I want to do something with these files , I'll load the file names back into an array and loop through that array to do my work:


Dim arySelected(lstSelected.Items.Count -1)
lstSelected.Items.CopyTo(arySelected, 0)

For i as Integer = 0 to arySelected.GetUpperBound(0)
'Work goes here. You can use the same DirectoryInfo from before
'combined with each item in your array to point at the files
'you want to manipulate.
Next


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1