Send XML to browser and force a save as dialog

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
 
L

Leon Mayne [MVP]

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.
 
R

Richard Wilde

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
 
L

Leon Mayne [MVP]

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

Leon Mayne [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top