Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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:
VB
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]
Posted
Updated 13-Jan-13 5:48am
v3
Comments
Sergey Alexandrovich Kryukov 13-Jan-13 14:11pm    
Why? why?!
—SA

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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Jan-13 19:08pm    
This will work this way, yes, (in more general case, HttpWebRequest would be needed), but who knows what OP's "requirements" meant? Of course, a 5.
—SA
Espen Harlinn 14-Jan-13 3:23am    
Thank you, Sergey :-D
VB
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.
 
Share this answer
 
v4
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
 
Share this answer
 
Comments
Espen Harlinn 13-Jan-13 17:54pm    
Good points :-D
Sergey Alexandrovich Kryukov 13-Jan-13 19:05pm    
Thank you, Espen.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900