Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
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]
Posted 13-Jan-13 5:45am
Edited 13-Jan-13 5:48am
ProgramFOX124.5K
v3
Comments
Sergey Alexandrovich Kryukov at 13-Jan-13 14:11pm
   
Why? why?!
—SA
Rate this: bad
good
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? Smile | :)
 
—SA
  Permalink  
Comments
Espen Harlinn at 13-Jan-13 17:54pm
   
Good points :-D
Sergey Alexandrovich Kryukov at 13-Jan-13 19:05pm
   
Thank you, Espen.
—SA
Rate this: bad
good
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
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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 at 14-Jan-13 3:23am
   
Thank you, Sergey :-D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
v4

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



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2014
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