cdoverlaw Posted June 28, 2004 Posted June 28, 2004 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 Quote
Administrators PlausiblyDamp Posted June 28, 2004 Administrators Posted June 28, 2004 http://www.xtremedotnettalk.com/showthread.php?t=84242&highlight=webclient+text Also if you're using .Net you should look at the classes under System.IO rather than using the legacy FileOpen, LineInput functions. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
cdoverlaw Posted June 28, 2004 Author Posted June 28, 2004 i dont understand how that post could help Quote
Leaders dynamic_sysop Posted June 28, 2004 Leaders Posted June 28, 2004 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 :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.