473,327 Members | 1,967 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,327 software developers and data experts.

How to save html page using C#

I am trying to save html page using C# because i want to save the page
on the server not on the client side.
I can do that using Javascript the problem that i am having i want to
save the page on the server.

Jun 22 '06 #1
2 39660

<fm*****@investec.co.za> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
I am trying to save html page using C# because i want to save the page
on the server not on the client side.
I can do that using Javascript the problem that i am having i want to
save the page on the server.


Exactly what do you want to save? Are you talking about a ASP.NET 2.0
applicaton from which you want to save the generated HTML before (or after)
sending it to the client? Or do you want to save the HTML from a random
remote web server? Or do you want to generate some HTML page and save
locally?

In either case, you'd probably want some code like this:

string htmlDocument = "<html><body>Hello world</body></html>";
FileStream fs = File.OpenWrite("C:\myfile.html");
StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
writer.Write(htmlDocument);
writer.Close();

...But of course, retrieving the actual HTML data is the challenge.

Frode Nilsen
Jun 22 '06 #2
Sample code:

private void Page_Load(object sender, System.EventArgs e)
{
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);
Page.RenderControl(oHtmlTextWriter);
oHtmlTextWriter.Flush();
System.IO.FileStream fs = new
System.IO.FileStream(@"C:\temp\test.htm",System.IO .FileMode.Create);
string s= oStringWriter.ToString();
byte[] b = System.Text.Encoding.UTF8.GetBytes(s);
fs.Write(b,0,b.Length);
fs.Close();
Response.End();
}

--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"fm*****@investec.co.za" wrote:
I am trying to save html page using C# because i want to save the page
on the server not on the client side.
I can do that using Javascript the problem that i am having i want to
save the page on the server.

Jun 22 '06 #3

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

Similar topics

3
by: lir | last post by:
Hi, I am trying to save a fram in a page using the execCommand("saveas") the html is save currectly but I can not save the gif on that page. How can I save the fram with the gif via...
10
by: Prakashsir | last post by:
I have desgined script to show div at runtime. Now I want to copy that newly created div and/or to save in normal html file so that i can see later. 1. When I select all the content or view its...
7
by: joseph.inglis | last post by:
I have a web browser object on a form which I have set to edit mode and use the UCOMIConnectionPointContainer interface to hook in and catch events. All working sweetly. Except there...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
3
by: fiefie.niles | last post by:
I would like to save a web page to a file and have the hyperlinks work when I bring the file back up. If the web page has a hyperlink like the following <a href="OurWeb/News/abcFile.htm">, after...
12
by: =?Utf-8?B?RnJlZU5FYXN5?= | last post by:
Hello, the scenario: There's an ASPX page which shows some text and has three buttons at the bottom: Save, Print and Close. Print and close is done by javascript. But how can I save the page...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
2
by: ppuniversal | last post by:
Hi All, My question is as follows: I have a text box and two links.Let the two links be - Show and Save . On clicking the Show , a web page is generated by fetching some data from database...
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...
0
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.