Ask a Question related to ASP.NET General, Design and Development.
-
Ken Cox [Microsoft MVP] #1
Re: Force File Download XML Problem
Below is some code I posted yesterday. Does it help?
Ken
MVP [ASP.NET]
Imports System.io
Public Class writexmlp
Inherits System.Web.UI.Page
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim ds As New DataSet
ds.ReadXml(Server.MapPath("a.xml"))
Dim xmlstream As New MemoryStream
ds.WriteXml(xmlstream)
Response.AppendHeader _
("Content-disposition", _
"attachment; filename=a.xml")
Response.ContentType = "application/download"
Response.BinaryWrite(xmlstream.ToArray())
Response.End()
End Sub
End Class
"PJS" <PJS@unite.com.au> wrote in message
news:3f1881c8_1@news.iprimus.com.au...
I have a site which generates a user specific XML document. The user then
selects "Save to PC" which then forces the browser to show the
"save/download" dialog box. The code used is as follows:
Response.AddHeader("Content-Disposition", "attachment; filename=" &
fileName)
Response.ContentType = "text/XML"
Response.WriteFile(fileName)
Response.End()
fileName is an XML document such as myXMLDoc.xml
This works perfectly for later Operating systems such as Windows XP and
Windows 2000 ( SP2 but not where SP1 is installed). The dialog box
automatically recognises the file format as XML and saves the file
correctly.
Earlier Operating Systems fail to recognise the XML format and unless
manually altered, save the file as a gobbly-glock text file.
Is there a work around where I can force earlier systems to save an XML file
as an XML file without the user having to manually enter the save as
filename with the XML extension?
With Thanks,
Peter
Ken Cox [Microsoft MVP] Guest
-
How to force File Download
A Web server that uses the Content-disposition: attachment HTTP header to force a file download should prompt the user to open or save the file;... -
Force Download
I've been trying to get the Bud force download (from Tom Much) to work with data pulled from a recordset ... however for some reason I cannot get it... -
Force download pdf
Hi I am trying to work out how download a pdf form a link in my Flash movie (actually download it not open it up) I have an extension to do this in... -
force a file download dialog does not work in 5.5 sp1
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel"... -
Force Download - XML problem
Thanks in advance. I have a site which generates a user specific XML document. The user then selects "Save to PC" which then forces the browser... -
PJS #2
Re: Force File Download XML Problem
Thanks Ken.
Older operating systems still just download the file as a "Document".
Windows XP correctly identifies the xml extension.
Your code works as long as the filename and extension is hard coded (such as
a.xml in your example). However, on the actual site the file itself is
dynamically generated as is the filename. For reasons I can't explain, when
the filename is dynamically created the file is downloaded as a "Document".
Once downloaded, if you then add the xml extension it works fine.
I guess the simple answer here is to tell users to ensure that the file is
correctly named after being downloaded.
Thanks,
Peter
"Ken Cox [Microsoft MVP]" <BANSPAMken_cox@sympatico.ca> wrote in message
news:OSWbu7YTDHA.1552@TK2MSFTNGP12.phx.gbl...file> Below is some code I posted yesterday. Does it help?
>
> Ken
> MVP [ASP.NET]
>
>
> Imports System.io
> Public Class writexmlp
> Inherits System.Web.UI.Page
>
>
> Private Sub Button1_Click _
> (ByVal sender As System.Object, _
> ByVal e As System.EventArgs) _
> Handles Button1.Click
> Dim ds As New DataSet
> ds.ReadXml(Server.MapPath("a.xml"))
> Dim xmlstream As New MemoryStream
> ds.WriteXml(xmlstream)
> Response.AppendHeader _
> ("Content-disposition", _
> "attachment; filename=a.xml")
> Response.ContentType = "application/download"
> Response.BinaryWrite(xmlstream.ToArray())
> Response.End()
> End Sub
> End Class
>
>
> "PJS" <PJS@unite.com.au> wrote in message
> news:3f1881c8_1@news.iprimus.com.au...
> I have a site which generates a user specific XML document. The user then
> selects "Save to PC" which then forces the browser to show the
> "save/download" dialog box. The code used is as follows:
>
> Response.AddHeader("Content-Disposition", "attachment; filename=" &
> fileName)
> Response.ContentType = "text/XML"
> Response.WriteFile(fileName)
> Response.End()
>
> fileName is an XML document such as myXMLDoc.xml
>
> This works perfectly for later Operating systems such as Windows XP and
> Windows 2000 ( SP2 but not where SP1 is installed). The dialog box
> automatically recognises the file format as XML and saves the file
> correctly.
>
> Earlier Operating Systems fail to recognise the XML format and unless
> manually altered, save the file as a gobbly-glock text file.
>
> Is there a work around where I can force earlier systems to save an XML> as an XML file without the user having to manually enter the save as
> filename with the XML extension?
>
> With Thanks,
>
> Peter
>
>
>
>
PJS Guest



Reply With Quote

