Skip to TLDR version if you aren't up for an explanation of my logical processing.
I've been fiddling around with a program which does the following: On button click, reads random line from a locally stored text document, without the ability to repeat itself
however what I wan't it to do is to be able to read from a URL, not a locally stored solution.
So my following code is the current function and what I tried, and what it resulted with.
string[] readText = File.ReadAllLines(@"path\file.txt");
Random rnd = new Random();
textBox1.Text=(readText[rnd.Next(readText.Length)]);
Naturally all this does is read from a file stored in the path section, then creates a random generator and makes the textbox' output a random line from the entire document.
What I tried to do with the URL, and it partially worked..
WebClient webCon= new WebClient();
string webData = webCon.DownloadString("URL");
textBox1.Text = webData;
followed by the following to generate a random line of the document:
Random rnd = new Random();
textBox1.Text = ((webData[rnd.Next(webData.Length-1)]));
However this was invalid and I then had to convert char to string the following way, which resulted in a really funny and utterly useless textbox.
Random rnd = new Random();
textBox1.Text = char.ToString((webData[rnd.Next(webData.Length-1)]));
TL;DR version
I have a program that reads from a local file with the following method:
string[] readText = File.ReadAllLines(path)
and then generates a random line from said document to display in a textbox like so:
Random rndm = new Random();
textBox1.Text=(readText[rndm.Next(readText.Length)]);
However what I want for it to be able to do, is read from a URL (online document). I tried completing this task with the webClient method but it resulted in needing to convert char to string on my textbox from a URL.
WebClient webCon= new WebClient();
string webData = webCon.DownloadString("URL");
textBox1.Text = webData;
I hope this question isn't close enough to a reposte as possible, I did ensure to check thoroughly first on relevant threads and couldn't really complete my task. Thank you in advance!