Download N Megabytes of a XML file



I want to download the first N Megabytes of huge XML File, so then I can close the broken tags with HTMLAgilityPack. Unfortunately, I can't use XMLReader.


I tried setting the Range on the HTTP Headers but that didn't seem to work, so now I'm trying this:



public string download(string url, int mb)
{
Int32 bytesToGet = 1048576 * mb;

HttpWebRequest request;
request = WebRequest.Create(url) as HttpWebRequest;
var buffer = new char[bytesToGet];
using (WebResponse response = request.GetResponse())
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
sr.Read(buffer, 0, bytesToGet);
}
}

return new string(buffer);
}


but this still doesn't work either. I tried it with mb=5 and I get just a few lines of the XML file.


No comments:

Post a Comment