将word文档保存到数据库中

来源:百度知道 编辑:UC知道 时间:2024/05/20 21:01:33
在C# winform中,如何把word文档转换成byte[],然后把byte[]转换成word文档,这怎么写啊,那个高手可以给出这两个方法啊先谢谢了,
高手你好啊,非常感谢你的方法,我还想问一个问题,就是save方法这里,你这里转换成word的时候是直接保存在本地了,可不可以不保存在本地,保存在内存中然后打开啊?

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace ConsoleApplication2
{
class Program
{
//把文件写入数据库
public void add(string pathName)
{
FileStream fs = new FileStream(pathName, FileMode.Open, FileAccess.Read);
byte[] buffByte = new byte[fs.Length];
fs.Read(buffByte, 0, (int)fs.Length);
fs.Close();
fs = null;
SqlConnection conn = new SqlConnection(@"data source=test;uid=sa;pwd=test;database=test");
string sqlstr = @"Insert into table1(doc) values(@img)";
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstr;
cmd.Connection = conn;
cmd.Par