我有一个显示用户可以编辑的表格的网络应用程序。在编辑过程中,原始表格的各种内部 HTML 被用户所做的编辑所取代。用户完成后,我想将结果表保存在 .html 文件中,这样我就可以将它包含在 PowerPoint 幻灯片中,而无需重新创建它。基本上我想在编辑后按原样捕获 .aspx 文件并将其写入文件。
如有任何建议,我们将不胜感激。
问候。
最佳答案
Basically I want to capture the .aspx file as is
因为您声明“捕获 ASPX”,所以我假设数据编辑保存在某个地方(内存/数据库)。这意味着可以直接覆盖控件/页面的 Render()
方法并将输出流重定向(或复制)到文件。
例子
protected override void Render( HtmlTextWriter writer ) {
using( HtmlTextWriter htmlwriter = new HtmlTextWriter( new StringWriter() ) ) {
base.Render( htmlwriter );
string renderedContent = htmlwriter.InnerWriter.ToString();
// do something here with the string, like save to disk
File.WriteAllText( @"c:\temp\foo.html", renderedContent );
// you could also Response.BinaryWrite() the data to the client
// so that it could be saved on the user's machine.
// and/or write it out to the output stream as well
writer.Write( renderedContent );
}
}
序列
- 用户输入数据
- 将结果存储在某处
- 您使用最新的内容重新呈现控件
- 捕获控件的输出并将其写入文件
关于c# - 将呈现的 HTML 写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11890913/