二进制文件的转换

visher 2006-06-01 10:16:26
各位大哥
我现在用VB.net和sql2000做一个软件
需要把文件以二进制文件存入数据库,现在存入已经解决了
问题是当读出文件时,我需要还原为原来文件的形式
如图片,word文档
图片我用Image.FromStream()能够还原
但是其他文件我不知道该怎么弄
比如还原word文件
请大家指导一下
谢谢
...全文
373 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
visher 2006-06-02
  • 打赏
  • 举报
回复
谢谢!
viena 2006-06-02
  • 打赏
  • 举报
回复
byte数组
二进制写文件
bhwhy 2006-06-02
  • 打赏
  • 举报
回复
string filePath=this.saveFileDialog1.FileName;

SqlConnection myConnection=new SqlConnection();
SqlCommand myCommand=new SqlCommand();

myConnection.ConnectionString=ConnectionString;
myConnection.Open();

string sql="select FileContent from Sys_NoStructureDatas where Sys_ID="+id;
myCommand.Connection=myConnection;
myCommand.CommandType=CommandType.Text;
myCommand.CommandText=sql;

SqlDataReader myDataReader=myCommand.ExecuteReader();

if(myDataReader.Read())
{
System.IO.FileInfo myFileInfo=new FileInfo(filePath);
System.IO.FileStream myFileStream=myFileInfo.Open(System.IO.FileMode.OpenOrCreate);

byte[] imgData=(byte[])myDataReader["FileContent"];
foreach(byte a in imgData)
{
myFileStream.WriteByte(a);

}

myFileStream.Close();
myDataReader.Close();

}

myConnection.Close();
MessageBox.Show("文件保存成功!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);

filePath是路径+文件名。
copico 2006-06-01
  • 打赏
  • 举报
回复
dim fr as new filestream("d:\123.doc",openorcreate)
dim dr as new streamwrite(fr)

dr.writebyByte()‘挨个读字节

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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