Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ibe got this code to open text files, but now i want to open text files that are on the internet and then show the text files text in a label, what changes wud i have to make to this code

 

Private Sub mnuOpenItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpenItem.Click
       Dim AllText, LineOfText As String
       OpenFileDialog1.Filter = "Text files (*.TXT)|*.TXT"
       OpenFileDialog1.ShowDialog() 'display Open dialog box
       If OpenFileDialog1.FileName <> "" Then
           Try 'open file and trap any errors using handler
               FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
               Do Until EOF(1) 'read lines from file
                   LineOfText = LineInput(1)
                   'add each line to the AllText variable
                   AllText = AllText & LineOfText & vbCrLf
               Loop
               lblNote.Text = OpenFileDialog1.FileName 'update label
               txtNote.Text = AllText 'display file
               txtNote.Select(1, 0)   'remove text selection
               txtNote.Enabled = True 'allow text cursor
               mnuCloseItem.Enabled = True 'enable Close command
               mnuOpenItem.Enabled = False 'disable Open command
           Catch
               MsgBox("Error opening file.")
           Finally
               FileClose(1) 'close file
           End Try
       End If
   End Sub

 

Thank you

 

Jonathan

  • Leaders
Posted

that post shows you how to open a file on the internet and read it ( for displaying or saving etc... )

the system.net.webclient allows you to do this easily , here's a quick example that may look a little easier to understand ...

[color=DarkGreen]'///download from the internet to a byte array...[/color]
       [color=Blue]Dim [/color] wClient [color=Blue]As New[/color] System.Net.WebClient
       [color=Blue]Dim[/color] bHtml [color=Blue]As Byte[/color]() = wClient.DownloadData("http://google.com")
       [color=DarkGreen]'/// you would specify the path of the text file where it says google.com[/color]
       [color=Blue]Dim[/color] html [color=Blue]As String[/color] = System.Text.Encoding.Default.GetString(bHtml)
       MessageBox.Show(html)
       wClient.Dispose()

hope it helps :)

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...