Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make downloadable file created by XmlDocument()

Tags:

xml

asp.net

I have created a file with

XmlDocument xmldoc = new XmlDocument();

Can I make this file as downloadable? without saving it?

like image 871
Vikas Avatar asked Dec 13 '25 04:12

Vikas


2 Answers

You could do something like:

XmlDocument doc = new XmlDocument();
doc.LoadXml(@"<xml>myxml</xml>");
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=MyXmlDocument.xml");
Response.AddHeader("Content-Length", doc.OuterXml.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Write(doc.OuterXml);
like image 71
Kev Avatar answered Dec 14 '25 20:12

Kev


This is how:

xmldoc.Save(Response.OutputStream)

Don't forget to set response mime type and other relevant properties so client browser will understand it as a file download.

like image 22
Robert Koritnik Avatar answered Dec 14 '25 18:12

Robert Koritnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!