找传奇、传世资源到传世资源站!

C#将word文件存入数据库与读取(Web版)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

最新版本,更新了老版本只能在本地导出WORD文档,新版本可以用于网站
from clipboard
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(); } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复