Ashish Khadye

Ashish Khadye

  • NA
  • 62
  • 5.2k

How to download kml file (Google earth file) on button click asp.netC#

Jun 25 2020 2:30 AM

Hello I have created webfrom in asp.net on which user can upload kml file (Google earth file)..I have saved uploaded filein folder and file path in database.

Now on download button click I have to give same file for download

I got file path from database but I am unable to write code for download funcionality

Below is my download button click code :
  1. protected void btndownloadkml_Click(object sender, EventArgs e) {  
  2.  con.Close();  
  3.  SqlCommand cmdkml = new SqlCommand("select * from FileMaster where ClientId='" + ddlclient.SelectedValue.ToString() + "' and FileType='KML' order by Srno DESC", con);  
  4.  con.Open();  
  5.  SqlDataReader sdrkml = cmdkml.ExecuteReader();  
  6.  if (sdrkml.HasRows) {  
  7.   sdrkml.Read();  
  8.   Response.ContentType = "application/vnd.google-earth.kml+xml";  
  9.   string s1 = sdrkml.GetValue(3).ToString();  
  10.   string s2 = sdrkml.GetValue(4).ToString();  
  11.   Response.AppendHeader("Content-Disposition""attachment; filename=" + s2);  
  12.   Response.TransmitFile(Server.MapPath(s2));  
  13.   Response.End();  
  14.  }  
  15. }

please suggest changes


Answers (1)