Page.Render do not render complete page

L

Lau Lei Cheong

Hello,

I'm writing a web page using ASP.NET that with send the page's HTML
content to user through e-mail. My plan is to dump the content to a file
then email it to user as attachment.

The following the part of the code I used:
[Begin of Quote]
StreamWriter MyWriter = myfile.CreateText();
MemoryStream renderedPage = new MemoryStream(10240);
Html32TextWriter myWriter = new Html32TextWriter(new
StreamWriter(renderedPage, System.Text.Encoding.UTF8));

this.Render(myWriter);
//Breakpoint I'm pointing at
renderedPage.Position = 0;
using (StreamReader sr = new StreamReader(renderedPage))
{
MyWriter.Write(sr.ReadToEnd());
sr.Close();
MyWriter.Close();
}
[End of Quote]

And the following is the fragment where the saved page on server stop at:

[Begin of Quote]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
.......
<tr>
<td bgcolor="#FFFFFF" align="center">2</td>
<td bgcolor="#FFFFFF">ABCDEFG</td>
<td bgcolor="#FFFFFF" align="center">2</td>
<td bgcolor="#FFFFFF">100</td>
<td bgcolor="#FFFFFF">200</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" align="center">3</td>
<td bgcolor="#FFFFFF">HIJKLMN</td>
<td bgcolor="#FFFFFF" align="center">1</td>
[End of Quote]

The problem is, whatever the code is called in Page_Load or Page_Unload
event, the HtmlWriter seems to stop writing somewhere less than 4400bytes,
where the actual HTML length should be 4937 bytes. I measures this at the
breakpoint stated in the enclosed code, by typing "? renderedPage.Length" in
the command window.

I've tried to increase the memory allocated to program, use byte[] to
replace MemoryStream, using RenderControl instead of Render, etc. but with
no luck.
It seems to be the problem with Html32TextWriter.

It's quite strange to me the place where it stopped because it's in the
middle of a group of rows generated from the code on-the-fly. And the page
shown on the browser rendered completely without problem.

Does anyone have idea on why does it happen, or how to work around it? Any
help would be appreciated.

Thank you in advance.

Regards,
Lau Lei Cheong
 
L

Lau Lei Cheong

Some information to add:

I've found that if I attach the "StreamWriter connected to the filestream"
to the Html32TextWriter directly, then everything is Ok. So the problem
should be on the MemoryStream.

It's pity to find that because in my plan, the next thing to do is to try to
write the content directly to the MailMessage.Body and send as HTML.

Any help to workaround this would be appreciated.

Regards,
Lau Lei Cheong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top