In my project when i click on a button it should generate excel file and in the middle of first line in excel file as a heading i should get as "my first excel file". I could not get it when i am trying with following code.Any ideas?. Thanks in advance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace listofdirectories
{
public partial class ExportToExcel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=practise.xls");
StreamWriter stw = new StreamWriter();
HtmlTextWriter htw = new HtmlTextWriter(stw);
stw.WriteLine("my first excel file");
response.End();
}
}
}