Private void daochu (string outtpye)
{
String name = "my" + DateTime. Now. ToString ("yyMMdd-hhmmss") + "File Export ";
System. Web. HttpContext hc = System. Web. HttpContext. Current;
Hc. Response. Clear ();
Hc. Response. Buffer = true;
Hc. Response. ContentEncoding = System. Text. Encoding. UTF8;
If (outtpye = "1 ")
{
Hc. Response. AddHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. UrlEncode (name, System. Text. Encoding. UTF8) + ". doc ");
Hc. Response. ContentType = "application/ms-word ";
}
Else if (outtpye = "2 ")
{
Hc. Response. AddHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. UrlEncode (name, System. Text. Encoding. UTF8) + ". xls ");
Hc. Response. ContentType = "application/ms-excel ";
}
System. IO. StringWriter sw = new System. IO. StringWriter ();
System. Web. UI. HtmlTextWriter htw = new System. Web. UI. HtmlTextWriter (sw );
This. DataGrid1.RenderControl (htw );
Hc. Response. Write (sw. ToString ());
Hc. Response. End ();
Response. Write ("<script language = javascript> window. opener = null; window. close (); </script> ");
}
________________________________________
Response. ContentType = "application/vnd. ms-excel"
Response. ContentType = "application/msword ";