i have looked and looked for this and so far all the code i've downloaded simply doesnt work.
this code (below) works fine - however it opens up the "save file Dialog" and requires that the user select the path to save the .html file.
how can i by-pass that and save the file myself to say - a virtual directory?
any help is greatly appreciated
thanks
rik

Response.Clear()
Response.Buffer = True
Response.ContentType = "application/html"
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.AddHeader("Content-Disposition", "attachment;filename=Test.html")
Response.Charset = ""
EnableViewState = False
Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
pnMyPanel.RenderControl(oHtmlTextWriter)
Response.Write(oHtmlTextWriter.ToString())
Response.Close()

Recommended Answers

All 7 Replies

I'm not 100% sure of what you are trying to do. Do you basically want to output a plain html file from a .aspx page? There are a few ways you could go about doing this. I changed your code around a little bit and this works on a test page that I put together:

Response.Clear()
Response.Buffer = True
Response.ContentType = "text/html"
Response.ContentEncoding = System.Text.Encoding.UTF8

Dim htmlReader As New System.IO.StreamReader("absolute file path of the html file you want to display")
Response.Write(htmlReader.ReadToEnd())
htmlReader.Close()

The file path would be the location of the html file on the server. If you can post more details about what you are trying to accomplish it would help.

Hope this helps.

i need to actually Write the .html file contents to a virtual folder. such as Dim vpath As String = Server.MapPath("myFile"). as soon as the user navigates to the .aspx page - they could still see that page. i just need some additional processing to "save" that as a separate .html file, without intervention from the user. hopefully that's a little more clear as to what im trying to do. thanks again. rik

i guess the "short" of it would be i want to by-pass the save-file-dialog (so the user is not involved) and save to a pre-determined folder

i guess the "short" of it would be i want to by-pass the save-file-dialog (so the user is not involved) and save to a pre-determined folder

most lilely not possible. the web browser is supposed to be sandboxed and allowing a site access to any path on disk without user intervention in that way would represent a security hole.

Are you trying to save to an .html file the resulting output of the .aspx page after it is finished rendering? What for?

i have looked and looked for this and so far all the code i've downloaded simply doesnt work.
this code (below) works fine - however it opens up the "save file Dialog" and requires that the user select the path to save the .html file.
how can i by-pass that and save the file myself to say - a virtual directory?
any help is greatly appreciated
thanks
rik

Response.Clear()
Response.Buffer = True
Response.ContentType = "application/html"
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.AddHeader("Content-Disposition", "attachment;filename=Test.html")
Response.Charset = ""
EnableViewState = False
Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
pnMyPanel.RenderControl(oHtmlTextWriter)
Response.Write(oHtmlTextWriter.ToString())
Response.Close()

....................................................................
how to give the .aspx page as the input to this coding

Not sure try like

this.rendercontrol()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.