Re: Force File Download XML Problem

Discussion in 'ASP .Net' started by Ken Cox [Microsoft MVP], Jul 19, 2003.

  1. 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" <> wrote in message
    news:...
    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], Jul 19, 2003
    #1
    1. Advertising

  2. Ken Cox [Microsoft MVP]

    PJS Guest

    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]" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > 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, Jul 21, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PJS

    Force Download - XML problem

    PJS, Jul 18, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    529
  2. Albano Alves

    Force File to Download

    Albano Alves, Feb 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    390
    Mark Rae
    Feb 15, 2005
  3. Sam --
    Replies:
    2
    Views:
    656
    Sam --
    Mar 17, 2005
  4. Kele
    Replies:
    0
    Views:
    2,816
  5. Frank
    Replies:
    11
    Views:
    3,012
    A Hess
    Dec 12, 2003
Loading...

Share This Page