// Save data in the Table control to Excel or Word Public Void Save (System.Web.ui.Control Source, DocumentType Type) {response.clear (); response.buffer = true; // Set the header information of HTTP, Coding format if (Type == DocumentType.excel) {// Excel Response.Appendheader ("Content-Disposition", "Attachment; FileName = Result.xls"); response.contenttype = "Application / MS-Excel";} else IF (Type == DocumentType.Word) {// Word Response.Appendheader ("Content-Disposition", "Attachment; FileName = Result.doc"); response.contenttype = "Application / MS-Word";} // setting encoding Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.GetEncoding ( "GB2312"); // close the view state of the control source.EnableViewState = false; // initialize HtmlWriter System.IO.StringWriter writer = new System.IO.StringWriter (); System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter (writer); source.RenderControl (htmlWriter); // output Response.Write (writer.ToString ()) Response.end ();} // The following is saving pictures public voi D savePic () {String path = server.mappath (".") @ "/ images / chart.jpeg"; filestream file = file.openread (path); byte [] content = new byte [file.length]; File.read (Content, 0, Content.length); file.close (); response.clear (); response.Appendheader ("Content-Disposition", "Attachment; FileName = chart.jpeg"); response.contentType = "image / jpeg"; // Set the header information of HTTP response.binaryWrite (content); // Output response.end ();}