Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,

I want to know that how can i save a aspx page into html file?
Posted
Updated 14-Apr-16 23:38pm

C#
// needs using System.Net and System.IO at the top of the page
WebClient client = new WebClient();

client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

Stream data = client.OpenRead("http://www.codeproject.com");
StreamReader reader = new StreamReader(data);
string html = reader.ReadToEnd();
data.Close();
reader.Close();
 
Share this answer
 
Open the ASPX page in a web browser such as Firefox or Google Chrome, and choose 'Save As' - you should have the option to save the page as an HTML file. Understand however that this is the rendered page - anything dynamic (which requires ASP code to be run) will not be dynamic any longer - you'll have the equivalent of a snapshot of the page.

As you asked about doing this programatically, try the code below:

C#
using (WebClient client = new WebClient ())
{
    // Download as a file OR
    client.DownloadFile("http://server/url.aspx", @"C:\result.html");

    // Download as a string.
    string htmlCode = client.DownloadString("http://server/url.aspx");
}
 
Share this answer
 
v2
Comments
Member 8214635 19-Oct-11 4:06am    
how can i do this with c# code
BobJanova 19-Oct-11 6:08am    
You can't, the server doesn't have access to the client's browser.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900