gpt4 book ai didi

c# - 如何将当前的aspx页面保存为html

转载 作者:太空狗 更新时间:2023-10-29 13:47:45 27 4
gpt4 key购买 nike

请告诉我如何在单击按钮时将当前页面保存为 html 页面。我的页面仅包含我在页面加载事件中填写的标签。

我为此使用了下面的代码,但它并没有保存(在 HTML 中)我在加载页面时看到的所有值(我认为它会在值加载到页面之前进行转换)。

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 字符串。

  StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
divForm.RenderControl(w);
string s = sw.GetStringBuilder().ToString();

然后基本上您只需将其写入字符串文件并将其保存为 HTML 扩展名。

System.IO.File.WriteAllText(@"C:\yoursite.htm", s);

关于c# - 如何将当前的aspx页面保存为html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3270417/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com