473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to generate HTML page from code?

I would like to generate a HTML page and mail it to a user. In order to
design the page, I would like to leverage the Web Form designer and
code-behind programming model, but instead of generating the page in
response to a browser request, I would like to generate the page from code
and fetch the HTML code into a string and use that as the mail body that I
send to a user by SMTP.

How can I do this?

Olav
Nov 19 '05 #1
3 1494
Why not just instantiate IE & navigate to ur webpage (aspx), & after it has
been loaded,
then get hold of the HTML using the PEMS of the IE object u've got.

"Olav Tollefsen" <x@y.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl...
I would like to generate a HTML page and mail it to a user. In order to
design the page, I would like to leverage the Web Form designer and
code-behind programming model, but instead of generating the page in
response to a browser request, I would like to generate the page from code
and fetch the HTML code into a string and use that as the mail body that I
send to a user by SMTP.

How can I do this?

Olav

Nov 19 '05 #2
On Sun, 30 Jan 2005 19:40:53 +0100 in
microsoft.public.dotnet.framework.aspnet, "Olav Tollefsen" <x@y.com>
wrote:
I would like to generate a HTML page and mail it to a user. In order to
design the page, I would like to leverage the Web Form designer and
code-behind programming model, but instead of generating the page in
response to a browser request, I would like to generate the page from code
and fetch the HTML code into a string and use that as the mail body that I
send to a user by SMTP.

How can I do this?

Olav


Hi Olav,

You could probably use the WebClient class for this. Assuming you have
already designed a form called Mail.html with the designer, the
following code will instantiate the page on the server, and grab the
response. You can then convert it to a string, and email it out to
your clients.

using System.Net;
....
WebClient wc = new WebClient();
Byte[] pageData = wc.DownloadData("http://localhost/Mail.html");
string sHtml = Encoding.ASCII.GetString(pageData);
....
MailMessage Message = new MailMessage();
Message.Body = sHtml;

I hope that gets you started,
Roger

Nov 19 '05 #3
Hello Olav,

You can do something like:

public string GetHtml()
{
MyAspx aspx = new MyAspx();
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
using (Html32TextWriter writer = new Html32TextWriter(sw))
{
aspx.RenderControl(writer);
}

return sb.ToString();
}

In this case, MyAspx is the class that your ASPX is.

--
Matt Berther
http://www.mattberther.com
I would like to generate a HTML page and mail it to a user. In order
to design the page, I would like to leverage the Web Form designer and
code-behind programming model, but instead of generating the page in
response to a browser request, I would like to generate the page from
code and fetch the HTML code into a string and use that as the mail
body that I send to a user by SMTP.

How can I do this?

Olav


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Rathtap | last post by:
I want to write a C# application (lets call it Generator) that will receive an argument(patient account number) and dynamically generate a series of linked HTML files (claim information, payments,...
1
by: A Traveler | last post by:
Hello, i am having this problem. The exact error message is: "Unable to generate code for a value of type 'System.Web.UI.Page'. This error occurred while trying to generate the property value for...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
6
by: ash | last post by:
i have a web page using frameset split into few pages. And I want to generate one page of HTML code and send it through email. My question is have to generate a HTML page using asp? Thx very much.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.