//fileLocal为文件路径
System.IO.FileStream fs = new System.IO.FileStream(fileLocal, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] fileData = br.ReadBytes(Convert.ToInt32(fs.Length));
fs.Read(fileData, 0, Convert.ToInt32(fs.Length));
fs.Close();
//fileData 这里已经转化为byte ,可以存储到SQL Server数据库,数据库字段类型为image
--------------------------------------------------------------------------------
//数据库读取byte/image字段,下载文件到本地
byte[] arbyte = null;
System.IO.FileStream fs = default(System.IO.FileStream);
SQL = "SELECT filebyte FROM table WHERE id='id';
//即从数据库中读取的byte字段
arbyte = FileContent[0].filecontent;
fs = new System.IO.FileStream(filelocal, FileMode.Create);
fs.Write(arbyte, 0, arbyte.Length);
fs.Flush();
fs.Close();
//filelocal下载到本地的文件路径
标签:fs,c#,数据库,System,FileStream,IO,byte From: https://www.cnblogs.com/jigeqiu/p/18058558