What exactly do you want to achieve? Do you just want to copy aspx file from one folder to another one or you want to save browser output as a html file?
<%@ Page Language="VB" AutoEventWireup="false" ValidateRequest="false" CodeFile="Default3.aspx.vb" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>View HTML</title>
<script type="text/javascript" language="javascript">
function sample(txtbox)
{
var src = document.documentElement.innerHTML;
document.forms[0]['txtsam'].value = src;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnViewHtml" runat="server" Text="View Html" />
<br />
<br />
<asp:TextBox ID="txtsam" runat="server" Height="235px" TextMode="MultiLine" Width="542px"></asp:TextBox></div>
</form>
</body>
</html>
Partial Class Default3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
btnViewHtml.Attributes.Add("onClick", "javascript:sample()")
End Sub
End Class
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Here is the code for saving the browser output on a button click (file will be saved in "Output" folder and the name of the file will be "test.htm" - you will have to adjust that to your needs):
You can't expect that you will get proper help if you write just a few words... Post your code, let us know on what line you get error and than we will be able to help you.
Honnappa
Participant
1112 Points
534 Posts
i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 07:26 AM|LINK
i Need to save the Current aspx page when i hit button...How to save the current aspx page to one folder?
My Profile
kipo
All-Star
16487 Points
2812 Posts
Re: i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 07:33 AM|LINK
What exactly do you want to achieve? Do you just want to copy aspx file from one folder to another one or you want to save browser output as a html file?
ramiramilu
All-Star
98053 Points
14516 Posts
Re: i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 07:49 AM|LINK
use HttpWebRequest to ping that page, and get its response as html...then use FileStream to write html content to a html page and save it on server - http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx
alternatively you can also use WebClient to get html response...
Thanks,
JumpStart
venkatmca008
Participant
1810 Points
341 Posts
Re: i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 08:09 AM|LINK
hi..try this..
<%@ Page Language="VB" AutoEventWireup="false" ValidateRequest="false" CodeFile="Default3.aspx.vb" Inherits="Default3" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>View HTML</title> <script type="text/javascript" language="javascript"> function sample(txtbox) { var src = document.documentElement.innerHTML; document.forms[0]['txtsam'].value = src; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btnViewHtml" runat="server" Text="View Html" /> <br /> <br /> <asp:TextBox ID="txtsam" runat="server" Height="235px" TextMode="MultiLine" Width="542px"></asp:TextBox></div> </form> </body> </html> Partial Class Default3 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load btnViewHtml.Attributes.Add("onClick", "javascript:sample()") End Sub End ClassMicrosoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Honnappa
Participant
1112 Points
534 Posts
Re: i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 08:48 AM|LINK
i need to save Browser output as html page in a Zip folder
My Profile
kipo
All-Star
16487 Points
2812 Posts
Re: i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 09:12 AM|LINK
Here is the code for saving the browser output on a button click (file will be saved in "Output" folder and the name of the file will be "test.htm" - you will have to adjust that to your needs):
protected void Button1_Click(object sender, EventArgs e) { ViewState["Export"] = true; } protected override void Render(HtmlTextWriter writer) { if (ViewState["Export"] != null && Convert.ToBoolean(ViewState["Export"])) { ViewState["Export"] = false; StringBuilder sb = new StringBuilder(); using (HtmlTextWriter tw = new HtmlTextWriter(new System.IO.StringWriter(sb))) { base.Render(tw); string sContent = sb.ToString(); using (StreamWriter sw = File.CreateText(Server.MapPath("~/test.htm"))) { sw.WriteLine(sContent); sw.Close(); } writer.Write(sContent); } } else { base.Render(writer); } }For zipping that file, use this library: http://dotnetzip.codeplex.com/
Honnappa
Participant
1112 Points
534 Posts
Re: i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 09:54 AM|LINK
According your code it will nt work
RegisterForEventValidation can only be called during Render();
My Profile
kipo
All-Star
16487 Points
2812 Posts
Re: i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 09:59 AM|LINK
You can't expect that you will get proper help if you write just a few words... Post your code, let us know on what line you get error and than we will be able to help you.
Honnappa
Participant
1112 Points
534 Posts
Re: i Need to save the Current aspx page as Html page when i hit button
Feb 29, 2012 10:22 AM|LINK
Sorry Kepo...Your code works Perfectly !!!
I was writing in Page load Event that was the problm
Thanks
My Profile