[2005] Force download prompt for xml file
I'm new to ASP .NET and Visual Basic .NET.
I'm sure this has been asked but a quick search didn't bring anything up for me that helped. What I want to do is convert a XmlDocument into a xml file and have it prompt the user to download the xml file when a button is clicked.
I don't know where to begin so any examples of how to convert a XmlDocument to a xml file and prompt to save that file would be great. Thanks
Re: [2005] Force download prompt for xml file
I think you need to change content type association while sending the XML document from server to client side. This article might help you.
Re: [2005] Force download prompt for xml file
Once you write the XmlDocument to disk, you can do Response.WriteFile().
Re: [2005] Force download prompt for xml file
Generally all XML files open up in the browser as their MIME types are defined. So I guess Response.WriteFile() will open the XML in browser (am I wrong?) but what OP wanted was to force download the file.
Re: [2005] Force download prompt for xml file
Like this:
Code:
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=myfile.xml");
Response.WriteFile("C:\\Documents and Settings\\blah\\Desktop\\myfile.xml");