using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, System.EventArgs e)
{
try
{
string str = TextBox1.Text.ToString().Trim();
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 = TextBox2.Text.ToString().Trim();
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
{
}
}
}