datagrid htmlコードのエクスポート


   :
1、       ,   html  ,   ,      
2、datagrid     、   ,    

    :
Response.Clear();
???Response.Buffer= false;
???Response.Charset="GB2312";
???Response.AppendHeader("Content-Disposition","attachment;filename=test.xls");
???Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312"); ???Response.ContentType = "application/ms-excel"; ???this.EnableViewState = false;
???System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
???System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
???this.DataGrid1.RenderControl(oHtmlTextWriter);
???Response.Write(oStringWriter.ToString());
???Response.End();

 
 
ASP.NET直下?IEで打つのではなく、ファイル?それは
.??皆さん、以下を使いますか?文:context.Response.ContentType = "application/octet-stream"; context.Response.AddHeader("Content-Disposition", "attachment;FileName="+ name); byte[] fileBuffer = new byte[fileSize]; fileStream.Read(fileBuffer, 0, (int)fileSize); context.Response.BinaryWrite(fileBuffer); context.Response.End(); ======================================
FileStream fileStream=new FileStream("C:\\doc\\test.doc",FileMode.Open); long fileSize = fileStream.Length; Context.Response.ContentType="application/octet-stream"; Context.Response.AddHeader("Content-Disposition","attachment; filename=\""+ HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8) + "\""); Context.Response.AddHeader("Content-Length",fileSize.ToString()); byte[] fileBuffer=new byte[fileSize]; fileStream.Read(fileBuffer, 0, (int)fileSize); fileStream.Close(); Context.Response.BinaryWrite(fileBuffer); Context.Response.End();
============================================int id = int.Parse(context.Request.QueryString["id"]);            string sendUserNo = context.Request.QueryString["sendUserNo"];            string receiveUserNo = context.Request.QueryString["receiveUserNo"];            Message message = new Message(id, sendUserNo, receiveUserNo);
            string name = context.Server.UrlEncode(message.FileName);
            string oppositeName = message.Filepath;            string absoluteName = context.Server.MapPath(message.Filepath);            FileStream fileStream = new FileStream(absoluteName, FileMode.Open,FileAccess.Read);            long fileSize = fileStream.Length;
            context.Response.ContentType = "application/octet-stream";            context.Response.AddHeader("Content-Disposition", "attachment;FileName="+ name);            byte[] fileBuffer = new byte[fileSize];            fileStream.Read(fileBuffer, 0, (int)fileSize);            context.Response.BinaryWrite(fileBuffer);            context.Response.End();