然后我想到了生成的Word文档让用户下载到本地,于是用一个Down.aspx,代码写如下:
namespace tiku
{
/// <summary>
/// down 的摘要说明。
/// </summary>
public class down : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string FullFileName = Request.QueryString["id"];
this.DoDownLoad("d://试题.doc");
}
private void DoDownLoad(string filePath)//filePath文件存在数据库中得路径。
{
int point=0;
point = filePath.LastIndexOf(@"/")+1;
string fileName = filePath.Remove(0,point);
// filePath=Server.MapPath(filePath);
Response.Clear();
Response.ClearHeaders();
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/octet-stream";
FileInfo fi = new FileInfo( filePath );
Response.AddHeader( "Content-Disposition","attachment; filename=" + HttpUtility.UrlEncode( fileName ) ) ;
Response.AddHeader( "Content-Length", fi.Length.ToString() );
byte[] tmpbyte = new byte[ 1024 * 8 ];
FileStream fs = fi.OpenRead();
int count;
while( (count = fs.Read( tmpbyte, 0, tmpbyte.Length ) ) > 0 )
{
Response.BinaryWrite( tmpbyte );
Response.Flush();
}
fs.Close();
Response.End();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
一个组卷系统搞定了^_^