//1。将path 所制定的文件转成byte[] 类型数据
byte[] b = File.ReadAllBytes(path);
//2。存到数据库的方法就不说了
注意的是 sql server 中存储btye[] 我用的是 Image 类型
oracle 中 我用的是 Blob 类型
//3。将byte[] 数据转换成指定
try
{
byte[] bt = "得到数据库中存储的 Blob(oracl) 或 Image(sql server) 数据";
string filename = path + "//" + file; // file 为上传时候文件带有后缀名的名称(一定要带有后缀名)
FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Write);
stream.SetLength(bt.LongLength);
stream.Write(bt, 0, bt.Length); //将二进制文件写到指定目录
stream.Close();
this.lab.Text = "保存成功!";
}
catch
{
this.lab.Text = "保存失败!!";
}