如何将数据库中的二进制数据另存为本地word文件

BlueRiver2003 2003-08-04 01:33:57
请教:我将word文件内容保存到数据库中
现在如何再将保存到表中的二进制数据另存为本地word文件不知道如何解决
...全文
85 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueRiver2003 2003-08-04
  • 打赏
  • 举报
回复
我知道了,把参数FileMode.Open修改为FileMode.Creat就OK了
谢谢 panyee(快乐王子)
BlueRiver2003 2003-08-04
  • 打赏
  • 举报
回复
可是运行到语句FileStream fs = new FileStream("e:\\123558.doc", FileMode.Open, FileAccess.Write);
出错"Could not find file "c:\123558.doc". "
怎么办:(

panyee 2003-08-04
  • 打赏
  • 举报
回复
原来是图片, 容易改成word
int ImgID = Convert.ToInt32(Request.Params["id"]);
string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(connStr);
string sql = "select * from t_imgs where id = @ImgID";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@ImgID", SqlDbType.Int).Value = ImgID;
conn.Open();
SqlDataReader read = cmd.ExecuteReader();
read.Read();
// Response.ContentType = (string)read["type"];
// Response.OutputStream.Write((byte[])read["imgData"], 0, (int)read["imgSize"]);
// Response.End();
byte[] bytes = read["imgData"];
FileStream fs = new FileStream("c:\\123.doc", FileMode.Open, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
conn.Close();
速马 2003-08-04
  • 打赏
  • 举报
回复
二进制方式读写文件,保存的时候扩展名doc

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧