Reputation: 43
I am trying to read a listbox from an online link for example: http://blahblah.com/list.txt into a listbox. each line into a new listbox item.
I could get around that by doing
dim wc as new webclient
textbox.text = wc.downloadstring("http://blahblah.com/list.txt")
then save it as a .txt file and then read it into a listbox line for line..
I'd like to skip that step and just read directly from the text file online..
Thank you and I will answer any questions you need for helping me with this code. Thanks a bunch.
Upvotes: 1
Views: 2847
Reputation: 125698
You can't read the individual lines directly from the file without downloading it first. It's only available as a text file; you have to retrieve the contents of that file before you can access them.
You can do it without saving it into an actual text file, however. Read the file content into a String
variable, use String.Split
to create an array containing the individual lines, and then add the items from that array into your ListBox
.
Dim Lines() As String
Dim stringSeparators() As String = {vbCrLf}
Dim Source As String
Dim wc as new WebClient
Source = wc.downloadstring("http://blahblah.com/list.txt");
Lines = Source.Split(stringSeparators, StringSplitOptions.None)
ForEach s As String in Lines
ListBox1.Items.Add(s)
Next
Upvotes: 3