Export data from html file to excel using fileupload in ASP.NET.
- if (FileUpload1.HasFile)
- {
- string Ext = Path.GetExtension(FileUpload1.PostedFile.FileName);
- if (Ext == ".html" || Ext == ".htm")
- {
- string filename = FileUpload1.PostedFile.FileName;
- int lastSlash = filename.LastIndexOf("\\");
- string trailingPath = filename.Substring(lastSlash + 1);
- string fullPath = Server.MapPath(" ") + "\\" + trailingPath;
- FileUpload1.PostedFile.SaveAs(fullPath);
- string fullPathnew = ConfigurationManager.AppSettings["Path"].ToString();
- string html = File.ReadAllText(Server.MapPath("~/" + fullPathnew));
- Response.Clear();
- Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
- Response.ContentType = "application/vnd.xls";
- Response.Cache.SetCacheability(HttpCacheability.NoCache);
- Response.Charset = "";
- Response.Output.Write(html);
- Response.End();
- }
- }