主题:[活动]求救!C# 读取image字段的问题
通过以下代码将word文件的内容以字节的形式保存到数据库的image字段后,
怎样将image字段的内容写回word文件呢??
byte[] content = new byte[info.Length]; //info为对应以读方式打开的word文件
FileStream stream = info.OpenRead();
stream.Read(content, 0, content.Length); //将word内容读入到byte[]中
stream.Close();
InsertCommand.Parameters["@Content"].Value = content;
try
{
conn.Open();
InsertCommand.ExecuteNonQuery();
}
finally
{
conn.Close();
}
我按以下方式实现,可是word文件的内容为乱码:[em10]
SqlDataReader reader = SelectCommand.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
FileStream stream = new FileStream(@"F:\11.doc",FileMode.OpenOrCreate,FileAccess.Write);
if (stream.CanWrite)
{
byte[] arr = (byte[])reader[2];
stream.Write(arr, 0, arr.Length);
MessageBox.Show(arr.ToString()); //输出结果为System.Byte[],为什么呢??
}
stream.Close();
}
reader.Close();
怎样将image字段的内容写回word文件呢??
byte[] content = new byte[info.Length]; //info为对应以读方式打开的word文件
FileStream stream = info.OpenRead();
stream.Read(content, 0, content.Length); //将word内容读入到byte[]中
stream.Close();
InsertCommand.Parameters["@Content"].Value = content;
try
{
conn.Open();
InsertCommand.ExecuteNonQuery();
}
finally
{
conn.Close();
}
我按以下方式实现,可是word文件的内容为乱码:[em10]
SqlDataReader reader = SelectCommand.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
FileStream stream = new FileStream(@"F:\11.doc",FileMode.OpenOrCreate,FileAccess.Write);
if (stream.CanWrite)
{
byte[] arr = (byte[])reader[2];
stream.Write(arr, 0, arr.Length);
MessageBox.Show(arr.ToString()); //输出结果为System.Byte[],为什么呢??
}
stream.Close();
}
reader.Close();