如何将当前的aspx页面保存为html [英] How to save current aspx page as html
问题描述
请告诉我如何将当前页面保存为点击按钮时的html页面。我的页面只包含我在页面加载事件中填写的标签。
Please tell me how to save current page as a html page on button click. My page contains only labels which I fill on page load event.
我使用下面的代码来完成此操作,但它不会保存(HTML)我看到我的页面何时加载(我认为它在页面加载之前进行转换)。
I am using the code below for this, but it's not saving (in HTML) all of the values that I see when my page is loaded (I think it converts before the values get loaded on the page).
private void saveCurrentAspxToHTML()
{
string HTMLfile = "http://localhost:4997/MEA5/AEPRINT.aspx?id=" +
Convert.ToString(frmae.AeEventid) +
"&eid=" +
Convert.ToString(frmae.AeEnquiryid);
WebRequest myRequest = WebRequest.Create(HTMLfile);
// Return the response.
WebResponse myResponse = myRequest.GetResponse();
// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(ReceiveStream, encode);
// Read 256 charcters at a time.
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
using (StreamWriter sw = new StreamWriter(Server.MapPath("~") + "\\MyPage.htm"))
{
while (count > 0)
{
// Dump the 256 characters on a string and display the string onto the console.
String str = new String(read, 0, count);
sw.Write(str);
count = readStream.Read(read, 0, 256);
}
}
// Close the response to free resources.
myResponse.Close();
}
请帮助我!
推荐答案
对于实际的代码,我有点粗略。但前一段时间我做了类似的事情。我使用StringWriter将aspx的内容写入html字符串。
I'm a little sketchy on the actual code. But a while ago I did something similar. I used a StringWriter to write the content of the aspx to html string.
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
divForm.RenderControl(w);
string s = sw.GetStringBuilder().ToString();
然后基本上你只需要把它写到一个字符串文件并保存为一个HTML扩展。
Then basically you just have to write that to a string file and save it as an HTML extension.
System.IO.File.WriteAllText(@"C:\yoursite.htm", s);
这篇关于如何将当前的aspx页面保存为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!