本文介绍了将aspx页面保存为html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好。 我有一个Web应用程序,需要将aspx页面保存为html文件。 aspx页面有一些服务器端控件,它们在运行时加载了值。我用来做的代码如下: Dim reportName 作为 字符串 = 完成报告 HttpContext.Current.Response.ContentType = application / html HttpContext.Current.Response.AddHeader( content-disposition, attachment; filename = CompletionReport - + Request.QueryString( ClientjobID)。修剪+ .html ) HttpContext.Current.Response.Charset = Dim tw As New System.IO.StringWriter Dim hw 作为 新 System.Web.UI.HtmlTextWriter(tw) HttpContext.Current.Response.Write(tw.ToString()) i在page_load事件中写了上面的代码。它会创建一个文件,但我遇到的问题是它在保存之前会提示保存对话框。我希望它直接保存在 Server.MapPath(〜\ UploadedDocs \)& test.html没有任何提示。 任何人都可以指导我这样做。 提前谢谢。 已添加代码块[/编辑] 解决方案 Dim sb As 新 StringBuilder() Dim hWriter As 新 HtmlTextWriter(新 StringWriter(sb)) MyBase .Render(hWriter) Dim PageResult As String = sb.ToString() writer.Write(PageResult) Dim sPath() As String sPath = System.IO.Directory.GetFiles(Server.MapPath( 〜\UploadedDocs), InvoicePrep& Request.QueryString( ClientJobID)& 。html 如果 sPath.Length> 0 然后 My.Computer.FileSystem.DeleteFile(sPath( 0 )) 结束 如果 Dim 文件作为 新系统.IO.StreamWriter(Server.MapPath( 〜\ UploadedDocs \)& InvoicePrep& Request.QueryString( ClientJobID)& 。html) file.WriteLine(PageResult) file.Close() 这是它的工作原理为了我。感谢大家的回复。 Hello everyonei have a web application where there is requirement to save the aspx page as html file. the aspx page has got some server side controls which get loaded with values at runtime. the code i am using to do is as follows:Dim reportName As String = "Completionreport"HttpContext.Current.Response.ContentType = "application/html"HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=CompletionReport-" + Request.QueryString("ClientjobID").Trim + ".html")HttpContext.Current.Response.Charset = ""Dim tw As New System.IO.StringWriterDim hw As New System.Web.UI.HtmlTextWriter(tw)HttpContext.Current.Response.Write(tw.ToString())i wrote the above code in page_load event. it creates a file but the problem i am facing is it is prompting with save dialog box before saving it. i want it to directly save in the Server.MapPath("~\UploadedDocs\") & "test.html" without any prompt.Can any one please guide me to do so.Thank you in advance.[Edit]Code block added[/Edit] 解决方案 这篇关于将aspx页面保存为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 17:31