Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET XML
hi all,
I have created a xml file using c# and I can save it at any location in my machine (in this situation I have saved it on the root of the application with name "temp.xml"), but I want to let it for the user to download it from their browser buy giving a link like-->
"click <a href="temp.xml" target="_blank">HERE</a> to download the file."
In Chrome and FireFox it show a new tab with only some values in my body part of the xml file but IE shows the whole xml. I want to download it in my download folder when anybody click on the above link.
thanks in advance for your support.
Posted 15-Jan-12 23:36pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

XML file can not be directly opened. you have to write following code to save on local system.
<asp:linkbutton id="lb_DownloadXML" runat="server" text="Download file" onclick="lb_DownloadXML_Click" xmlns:asp="#unknown"></asp:linkbutton>
protected void lb_DownloadXML_Click(object sender, EventArgs e)
        string strFullPath = Server.MapPath("~/temp.xml");        
        string strContents = null;
        System.IO.StreamReader objReader = default(System.IO.StreamReader);
        objReader = new System.IO.StreamReader(strFullPath);
        strContents = objReader.ReadToEnd();
        string attachment = "attachment; filename=test.xml";
        Response.ContentType = "application/xml";
        Response.AddHeader("content-disposition", attachment);
Hope this may help you...
tanweer akhtar at 16-Jan-12 5:27am
Thanks for the great reply.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

thnak you . it is for download single xml file. please provide solution for download multiple xml files at time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 205
1 Zoltán Zörgő 200
2 Peter Leow 160
3 BillWoodruff 85
4 CPallini 70
0 Sergey Alexandrovich Kryukov 9,568
1 OriginalGriff 6,901
2 Peter Leow 4,737
3 Zoltán Zörgő 4,404
4 CHill60 2,932

Advertise | Privacy | Mobile
Web04 | 2.8.150129.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100