c#将文件以二进制形式存入数据库
二进制在mssql数据库中是VARBINARY(max)
将文件转换为二进制
public byte[] getContent(string path) { System.IO.FileStream fs = new System.IO.FileStream(@path, System.IO.FileMode.Open); fs.Position = 0; byte[] content = new byte[fs.Length]; fs.Read(content, 0, (int)fs.Length); fs.Close(); return content; }
将二进制转换为文件
public void save(byte[] content,string path) { System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create); System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs); bw.Write(content, 0, content.Length); bw.Close(); }
数据库存取的话 就是个普通的insert,select就可以了