string sqlMetni = "SELECT * FROM blabla";
SqlDataAdapter da = new SqlDataAdapter(sqlMetni, Connection.Conn);
DataTable dt = new DataTable();
da.Fill(dt);
DataView raporDataView = new DataView(dt);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=uye_listesi.xls");
StringBuilder icerik = new StringBuilder();
icerik.Append("<table border='1'>" +
"<tr style='text-align:center; font-weight: bold; background-color: black; color: white;'>" +
"<td>Email</td>" +
"<td>CreationDateTime</td>" +
"</tr>");
foreach (DataRowView satir in raporDataView)
{
icerik.Append("<tr>");
icerik.Append("<td>" + satir["Email"].ToString() + "</td>");
icerik.Append("<td>" + satir["CreationDateTime"].ToString() + "</td>");
icerik.Append("</tr>");
}
icerik.Append("</table>");
HttpContext.Current.Response.Write(icerik);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();