Send XML to browser and force a save as dialog

  • Thread starter Thread starter Richard Wilde
  • Start date Start date
R

Richard Wilde

How do I force an XML document to be downloaded from a web browser to a
client?

The XML document will come ideally from a dataset but if this is not
possible then I can save off the XML document to the server and read it back
in to send to the clients browser. I have somethink like this but am
struggling to send the XML...


With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "text/xml"
.AddHeader("Content-Disposition", "attachment; filename=rippo.xml")
.Write(SOMEXMLFILE OR A DATASET)
.End()
End With

Can any one help?

Thanks
Rippo
 
Richard said:
How do I force an XML document to be downloaded from a web browser to
a client?

Change the content-type header to something their browser won't recognise,
like "text/doesntexist". This will force their browser to prompt to download
it.
 
Ah thank you. That solves half the problem.

I just realised that I did not structure my question.

Can you help me to solve the problem of reading in a XML from disk (or using
a dataset ideally) and finishing my code in the line .Write

With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "text/xml"
.AddHeader("Content-Disposition", "attachment; filename=rippo.xml")
.Write(SOMEXMLFILE OR A DATASET)
.End()
End With

Many thanks
Rippo
 
Richard said:
Can you help me to solve the problem of reading in a XML from disk
(or using a dataset ideally) and finishing my code in the line .Write

How about something like:

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Response.Clear()
Response.ContentType = "text/doesntexist"
Response.AddHeader("Content-type", "text/doesntexist")
Response.Write("Some text")
Response.End()
End Sub

Replace the "some text" with the output of your XML object (dataset?)
 
Leon Mayne [MVP] wrote:
<snip>

Sorry, use this instead:

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-type", "application/octet-stream")
Response.AddHeader("Content-Disposition", "attachment;
filename=""text.xml""")
Response.Write("Some text")
Response.End()
End Sub
 
Back
Top