Export Data from HTML File to Excel using Fileupload in ASP.NET

Export data from html file to excel using fileupload in ASP.NET. 
  1. if (FileUpload1.HasFile)  
  2. {  
  3.     string Ext = Path.GetExtension(FileUpload1.PostedFile.FileName);  
  4.     if (Ext == ".html" || Ext == ".htm")  
  5.     {  
  6.         string filename = FileUpload1.PostedFile.FileName;  
  7.         int lastSlash = filename.LastIndexOf("\\");  
  8.         string trailingPath = filename.Substring(lastSlash + 1);  
  9.         string fullPath = Server.MapPath(" ") + "\\" + trailingPath;  
  10.         FileUpload1.PostedFile.SaveAs(fullPath);  
  11.         string fullPathnew = ConfigurationManager.AppSettings["Path"].ToString();  
  12.         string html = File.ReadAllText(Server.MapPath("~/" + fullPathnew));  
  13.         Response.Clear();  
  14.         Response.AddHeader("Content-Disposition""attachment;filename=" + filename + ".xls");  
  15.         Response.ContentType = "application/vnd.xls";  
  16.         Response.Cache.SetCacheability(HttpCacheability.NoCache); // not necessarily required  
  17.         Response.Charset = "";  
  18.         Response.Output.Write(html);  
  19.         Response.End();  
  20.     }