Override Render of a page / StreamReader size limit?
So, I'm playing around with getting the HTML out of a standard ASP.Net Page. I've overridden the Render method, as so:
protected override void Render(HtmlTextWriter writer)
{
MemoryStream memoryStream = new MemoryStream();
try
{
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
{
var textWriter = new HtmlTextWriter(streamWriter);
base.Render(textWriter);
memoryStream.Position = 0;
using (StreamReader reader = new StreamReader(memoryStream))
{
va开发者_如何学Gor text = reader.ReadToEnd();
Response.Write(text);
reader.Close();
}
}
}
catch(ObjectDisposedException)
{
// The stream writer is already disposed?
}
finally
{
memoryStream.Dispose();
}
}
This works great on files that are less than 8.00 KB (8,200 bytes). If the file is larger than that, any text at the end is being cut off.
Does anyone have an suggestions?
Maybe, textWriter.Flush()
after a call to base.Render()
will save your day.
精彩评论