Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to read from a website, one line at a time?

Tags:

c#

I have this code:

string downloadedString;
System.Net.WebClient client;

client = new System.Net.WebClient();

downloadedString = client.DownloadString(
     "http://thebnet.x10.mx/HWID/BaseHWID/AlloweHwids.txt");

It's a HWID-type security (it will check your HWID to see if you are allowed to use the program)

Anyway, I want to be able to put multiple lines on it at a time, example:

xjh94jsl <-- Not a real HWID
t92jfgds <-- Also not real

And be able to read each line, one by one, and update it to downloadedString.

like image 801
Minicl55 Avatar asked May 31 '12 01:05

Minicl55


1 Answers

Don't download the url as a string, read it as a stream.

using System.IO;
using System.Net;

var url ="http://thebnet.x10.mx/HWID/BaseHWID/AlloweHwids.txt";
var client = new WebClient();
using (var stream = client.OpenRead(url))
using (var reader = new StreamReader(stream))
{
    string line;
    while ((line = reader.ReadLine()) != null)
    {
        // do stuff
    }
}
like image 190
Jeff Mercado Avatar answered Oct 13 '22 17:10

Jeff Mercado