This project has moved. For the latest updates, please go here.

modify output on the fly

Topics: Developer Forum, Project Management Forum, User Forum
Mar 26, 2007 at 10:44 AM
hi to all. i would like to know how can i modify the output of an .aspx page on the fly.
i'm developing a cms engine, and have this dir structure:


with an http handler i rewrite paths so i can use paths like;
/it/mypage.aspx (tha reads /templates/template0/page.aspx)

tha problem is that i would like to parse and modify the outputstream ON-THE-FLY so i can adjust images paths (and other tag attributes)...
i try to use:

private void parseMe()
HtmlDocument doc = new HtmlDocument();


but it tells me: "Stream was not readable".
obviously i miss something: can someone help me ?
cheers, Antonio. :-)
Jan 14, 2013 at 8:38 PM

Bump for this issue. I'm seeing it myself.

Using .NET 4.5 and HtmlAgilityPack 1.4.6:


using (var client = new WebClient())
using (var stream = client.OpenRead(uri))
    var html = new HtmlDocument();
    html.Load(stream); // throws here
    // ...

I checked in WireShark, and the content was transferred across the wire successfully and in full.

The exception is ArgumentException: Stream was not readable.

mscorlib.dll!System.IO.StreamReader.StreamReader(System.IO.Stream stream, System.Text.Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen) + 0x168 bytes
mscorlib.dll!System.IO.StreamReader.StreamReader(System.IO.Stream stream, System.Text.Encoding encoding) + 0x1d bytes  
HtmlAgilityPack.dll!HtmlAgilityPack.HtmlDocument.Load(System.IO.Stream stream) Line 517 + 0x40 bytes C#

Jan 14, 2013 at 9:00 PM

What's more, if I run this on the stream returned by OpenRead(uri)

new StreamReader(stream).ReadToEnd()

I get the full string, as expected.

In the end, the only way I found was to pass a string to HtmlDocument.Load. I suspect there is a bug in the stream processing code of the various HtmlDocument.Load overloads.