Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

here is the deal. I have an xml file that I want to read. my load function works perfectly... it takes a string filename from the loaddialogbox. this is then sent and included in the recent files menu. when selected I get the filename back that I wanted, the file opens but somereason fails to load. any suggestions? here is the code.

-----

-- this one works....

Private Sub MenuItemLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemLoad.Click

' Declare a FileInfo object for the config file.

Dim strTemp As String

OpenFileDialog1.Filter = "Xml files (*.XML)|*.XML"

OpenFileDialog1.ShowDialog()

Dim XmlDocument As System.Xml.XmlTextReader

Dim q As Integer

q = 0

'MsgBox()

If OpenFileDialog1.FileName <> "" Then

 

ListView1.Clear()

SetColumnNames()

ListView1.View = View.Details

Me.Refresh()

Try

XmlDocument = New System.Xml.XmlTextReader(OpenFileDialog1.FileName.ToString)

Catch

MsgBox("Error Opening File")

Exit Sub

End Try

Try

Dim l As ListViewItem

Dim x As Integer

x = 0

Do While (XmlDocument.Read())

If XmlDocument.Name.ToString = "Link" Then

Dim linkinfo(2) As String

Dim elementholder As String

elementholder = XmlDocument.ReadElementString()

linkinfo = elementholder.Split(",")

l = New ListViewItem(linkinfo(0))

l.Font = New Font("Courier new", 10, FontStyle.Underline)

l.ForeColor = Color.MediumBlue

l.UseItemStyleForSubItems = False

l.SubItems.Add(linkinfo(1))

l.SubItems.Add(linkinfo(2))

ListView1.Items.Add(l)

Me.Refresh()

 

End If

Loop

Catch ex As Exception

'MsgBox(ex)

MsgBox("error in loading file")

Exit Try

Finally

XmlDocument.Close()

End Try

Me.Refresh()

End If

End Sub

 

--- This one fails.

Dim XmlDocument As System.Xml.XmlTextReader

ListView1.Clear()

SetColumnNames()

ListView1.View = View.Details

Me.Refresh()

 

'MsgBox(CType(sender, MenuItem).Text.ToString)

'Exit Sub

Dim myFile As String

myFile = CType(sender, MenuItem).Text.ToString

MsgBox("MyFILE: " & myFile)

Dim mystring As String

 

If Len(myFile) > 0 Then

Try

mystring = CType(sender, MenuItem).Index.ToString

XmlDocument = New System.Xml.XmlTextReader(mystring)

Catch

MsgBox("Error Opening File")

Exit Sub

End Try

 

Dim l As ListViewItem

Dim x As Integer

x = 0

Try

Do While (XmlDocument.Read())

'MsgBox(XmlDocument.Name.ToString)

If XmlDocument.Name.ToString = "Link" Then

Dim linkinfo(2) As String

Dim elementholder As String

elementholder = XmlDocument.ReadElementString()

linkinfo = elementholder.Split(",")

l = New ListViewItem(linkinfo(0))

l.Font = New Font("Courier new", 10, FontStyle.Underline)

l.ForeColor = Color.MediumBlue

l.UseItemStyleForSubItems = False

l.SubItems.Add(linkinfo(1))

l.SubItems.Add(linkinfo(2))

ListView1.Items.Add(l)

Me.Refresh()

End If

Loop

Catch ex As Exception

 

 

-- exception always is right here....

 

MsgBox("EXCEPTION READING FILE VALUE: " & XmlDocument.Name.ToString)

MsgBox("File Opened, error in load")

Exit Try

Finally

XmlDocument.Close()

End Try

Me.Refresh()

'MsgBox("Under Construction")

 

End If

End Sub

 

anyway. I'm confused as why if the file is there and it opens, (it's there, and in correct format). but fails on the read....

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...