将aspx页面保存为html [英] Save aspx page as html
问题描述
大家好。
我有一个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
没有任何提示。
任何人都可以指导我这样做。
提前谢谢。
已添加代码块[/编辑]
这是一个想法:访问你的网址页面使用 HttpClient [ ^ ]类。这样你就可以强制页面将自己呈现为html。
祝你好运
Espen Harlinn
< blockquote>
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()
这是它的工作原理为了我。感谢大家的回复。
要求并没有明确的原因:ASPX页面并不存在。这是一个纯粹的编程工件,只存在于服务器端,并且仅在HTTP响应中产生真实页面(可能是HTML页面,但也可能是其他页面),以响应某些HTTP请求。因此,在一般情况下,它甚至不是任何特定HTTP页面的一对一通信,因为它的内容实际上取决于史前史(考虑会话状态),更通常取决于HTTP请求的内容。 br />
这样,你想要的东西一般不存在。
另一方面,一个HTML页面始终存在于客户端(当然,仅适用于具有text / html内容类型的HTTP请求),并且用户始终通过浏览器的View / Page Source或Save Page As获取它。那么,有什么可以帮助用户点击键盘按键或鼠标按键?在某种程度上,这是可能的,但为什么呢? :-)
-SA
Hello everyone
i 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.StringWriter
Dim 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]
Here is an idea: Access the url of your page using the HttpClient [^] class. This way you will force the page to render itself as html.
Best regards
Espen Harlinn
Dim sb As New StringBuilder() Dim hWriter As New HtmlTextWriter(New 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" If sPath.Length > 0 Then My.Computer.FileSystem.DeleteFile(sPath(0)) End If Dim file As New System.IO.StreamWriter(Server.MapPath("~\UploadedDocs\") & "InvoicePrep" & Request.QueryString("ClientJobID") & ".html") file.WriteLine(PageResult) file.Close()
This is how it is working for me. Thanks to all of you for your response.
The "requirement" does not make a distinct sense by a simple reason: such thing as "ASPX page" does not really exist. This is a pure programming artifact which exists only on a server side and produces a "real" page (which may be an HTML page, but also can be something else) only in HTTP response, in response to some HTTP request. So, in general case, it is not even one-to-one correspondent to any particular HTTP page, because the content of it really depends on prehistory (think about session state), and more typically, on the content of HTTP request.
This way, what you want does not generally exist.
From the other hand, an HTML page always exists on the client side (of course, only for HTTP requests with "text/html" content type), and the user always have it through the browser''s "View / Page Source" or "Save Page As". So what, what to help the user to click the keyboard keys or mouse buttons? To certain extent, this is possible, but why? :-)
—SA
这篇关于将aspx页面保存为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!