Click here to Skip to main content
Rate this: bad
good
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 22:36pm
tanweer13.5K
Rate this: bad
good
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();
        objReader.Close();
 
        string attachment = "attachment; filename=test.xml";
        Response.ClearContent();
        Response.ContentType = "application/xml";
        Response.AddHeader("content-disposition", attachment);
        Response.Write(strContents);
        Response.End();        
    }
 
Hope this may help you...
  Permalink  
Comments
tanweer akhtar at 16-Jan-12 5:27am
   
Thanks for the great reply.
Rate this: bad
good
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
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
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