Force File Download XML Problem

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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;...
    2. 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...
    3. 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...
    4. 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"...
    5. 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...
  3. #2

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

    PJS Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139