Reading multiple XML Files
Reading multiple XML Files
Reading multiple XML Files
Reading multiple XML Files
Reading multiple XML Files
Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files
Reading multiple XML Files Reading multiple XML Files
Reading multiple XML Files
Go Back  Xtreme Visual Basic Talk > > > Reading multiple XML Files


Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2010, 09:56 PM
jason123 jason123 is offline
Newcomer
 
Join Date: Aug 2010
Posts: 2
Default Reading multiple XML Files


Ok I have a VERY basic knowledge of VB. I'm having trouble figuring out how to read multiple xml files when a user selects them from a listbox. Below is what I have so far. Currently this will only read one xml file. When I change "Dim strDir As String = PlayListBox.SelectedItem" to "Dim strDir As String = PlayListBox.SelectedItems" the code doesn't work. Can someone please explain why using "selecteditems" doesn't work and the best way to resolve the issue. Thanks.
Code:
  Dim selectedFiles As New List(Of String)()
        Dim strDir As String = PlayListBox.SelectedItem
        Dim Readlist As XmlTextReader = New XmlTextReader((My.Computer.FileSystem.ReadAllText("C:\playlistlocation.txt") & "\" & strDir & ".wpl"))



       

            Me.SelectedMusicBox.Items.Clear()

            If PlayListBox.SelectedItem = "" Then
                MsgBox("Select A Playlist")
            Else
                
                While Readlist.Read()

                    If Readlist.NodeType = XmlNodeType.Element Then
                        If Readlist.LocalName.Equals("media") Then
                            SelectedMusicBox.Items.Add(Readlist.GetAttribute(0).ToString())
                            
                        End If
                    End If

                End While
Reply With Quote
  #2  
Old 08-18-2010, 02:13 AM
PlausiblyDamp's Avatar
PlausiblyDampReading multiple XML Files PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

When you do Dim strDir As String = PlayListBox.SelectedItem you are declaring a variable called strDir as a string and assigning a string to it - hence it works.

PlayListBox.SelectedItems however is of type SelectedObjectCollection and not a string - hence it doesn't work.

You will need to loop over the selected items and process each in turn.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 08-19-2010, 09:14 PM
jason123 jason123 is offline
Newcomer
 
Join Date: Aug 2010
Posts: 2
Default

PlausiblyDamp thanks for the input. The code below works, just thought I should give back.
Code:
   Me.SelectedMusicBox.Items.Clear()

            For i As Integer = 0 To PlayListBox.SelectedItems.Count - 1
                Dim strDir As String = PlayListBox.SelectedItems(i)




                Dim Readlist As XmlTextReader = New XmlTextReader((My.Computer.FileSystem.ReadAllText("C:\playlistlocation.txt") & "\" & strDir & ".wpl"))



                If PlayListBox.SelectedItem = "" Then
                    MsgBox("Select A Playlist")
                Else
                    'lblFileSize.Text = 0
                    While Readlist.Read()

                        If Readlist.NodeType = XmlNodeType.Element Then
                            If Readlist.LocalName.Equals("media") Then
                                SelectedMusicBox.Items.Add(Readlist.GetAttribute(0).ToString())
                                
                            End If
                        End If
                    End While
                End If
            Next
Reply With Quote
Reply

Tags
listbox, read multiple xml files, xml reader


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Reading multiple XML Files
Reading multiple XML Files
Reading multiple XML Files Reading multiple XML Files
Reading multiple XML Files
Reading multiple XML Files
Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files Reading multiple XML Files
Reading multiple XML Files
Reading multiple XML Files
 
Reading multiple XML Files
Reading multiple XML Files
 
-->