Diimplementasikan dalam acara klik tombol berikut:
private void btnMIME_Click(pengirim objek, System.EventArgs e)
{
BindData();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Disposisi Konten", "inline;namafile="
+ HttpUtility.UrlEncode("Unduh file.xls",Encoding.UTF8 ) );
//Jika outputnya adalah Word, ubah menjadi kode berikut
//Response.ContentType = "aplikasi/ms-word"
//Response.AddHeader("Disposisi Konten", "inline;namafile=test.doc")
StringBuilder sb=StringBuilder baru();
System.IO.StringWriter sw = Sistem.IO.StringWriter(sb) baru;
System.Web.UI.HtmlTextWriter hw = Sistem.Web.UI.HtmlTextWriter(sw) baru;
sb.Tambahkan("