Click here to Skip to main content
13,446,310 members (38,036 online)
Rate this:
Please Sign up or sign in to vote.
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:
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)

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 13-Jan-13 5:45am
Updated 13-Jan-13 5:48am
Sergey Alexandrovich Kryukov 13-Jan-13 14:11pm
Why? why?!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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
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.
Espen Harlinn 14-Jan-13 3:23am
Thank you, Sergey :-D
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Dim sb As New StringBuilder()
Dim hWriter As New HtmlTextWriter(New StringWriter(sb))
Dim PageResult As String = sb.ToString()
Dim sPath() As String
sPath = System.IO.Directory.GetFiles(Server.MapPath("~\UploadedDocs"), "InvoicePrep" & Request.QueryString("ClientJobID") & ".html"

           If sPath.Length > 0 Then
           End If

           Dim file As New System.IO.StreamWriter(Server.MapPath("~\UploadedDocs\") & "InvoicePrep" & Request.QueryString("ClientJobID") & ".html")

This is how it is working for me. Thanks to all of you for your response.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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? :-)

Espen Harlinn 13-Jan-13 17:54pm
Good points :-D
Sergey Alexandrovich Kryukov 13-Jan-13 19:05pm
Thank you, Espen.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02-2016 | 2.8.180314.2 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100