<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml" >
无标题页
default4.aspx.cs:
protected void Button1_Click(object sender, System.EventArgs e)
{
try
{
string str = "";
for(int page=0; page<4; page++)
{
str += "
";
str += "描述 |
";
for(int i=1; i< 10; i++)
{
str =str + "测试" + i.ToString() + " |
";
}
str +="
";
//.doc 换页
str +="
";
}
str += "";
byte[] buff = System.Text.Encoding.Unicode.GetBytes(str);
//byte[] buff = System.Text.Encoding.UTF8.GetBytes(str);
byte[] outBuff = new byte[buff.Length + 2];
// 使用文件流方式写入UniCode编码的doc文件。
byte[] mark = {0xFF,0xFE} ;
outBuff[0] = mark[0];
outBuff[1] = mark[1];
for(int i=0; i< buff.Length; i++)
{
outBuff[i+2] = buff[i];
}
Context.Response.ContentType="application/octet-stream";
string fileName = "测试.doc";
Context.Response.AddHeader("Content-Disposition","attachment; filename=\"" + HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8) + "\"");
Context.Response.AddHeader("Content-Length",outBuff.Length.ToString());
Response.BufferOutput = true;
Response.Clear();
Context.Response.BinaryWrite(outBuff);
Context.Response.End();
}
catch(Exception ex)
{
ex.ToString();
}
finally
{
}
}
本文作者:佚名 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow