最新版本,更新了老版本只能在本地导出WORD文档,新版本可以用于网站 
 
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.IO;using testModels;using testBLL;namespace test{  public partial class _Default : System.Web.UI.Page  {    protected void Page_Load(object sender, EventArgs e)    {    }    protected void Button1_Click(object sender, EventArgs e)    {      Stream fileStream = fulPath.PostedFile.InputStream;      //获取上传文件字节的大小      int length = fulPath.PostedFile.ContentLength;      byte[] wordData = new byte[length];      //从流中读取字节并写入wordData            int n = fileStream.Read(wordData, 0, length);      //下面把wordData保存进数据库      Words wd = new Words();      wd.name = TextBox1.Text.Trim();      wd.wordData = wordData;      WordsManage.AddWords(wd);    }    /// <summary>    /// 根据TextBox2传入的文件名调出WORD文档    /// </summary>    /// <param name="sender"></param>    /// <param name="e"></param>    protected void Button2_Click(object sender, EventArgs e)    {            Context.Response.Buffer = true;      Context.Response.Clear();      Context.Response.ContentType = "application/msword";      Context.Response.AddHeader("Content-Disposition", "attachment;filename="  HttpUtility.UrlEncode(TextBox2.Text.Trim()  ".doc", System.Text.Encoding.UTF8));      Context.Response.BinaryWrite(WordsManage.GetBtBybh(TextBox2.Text.Trim()));      Context.Response.Flush();      Context.Response.End();     }  }}

 
  
					
				
评论