Click here to Skip to main content
13,050,429 members (81,022 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 22: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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2017
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