I got a column with Data Type of Image in SQL Server. What I would like to do is to omit this data to a FileStream or to a file. I tried to read the data using LINQ and I found the data type detected for that particular column is System.Data.Linq.Binary. I was expecting it to be Byte Data type. So I need to convert the Binary to byte then to File Stream. But I found a simpler way by using “ToArray” properties and cast it back to byte solves my problem.
foreach (tblExpReceiptFile file in ExpReceiptFactory.tblExpReceiptFileSelect()) { string fileName = file.vcFileName.Replace(" ","_"); FileStream fileStream = File.Create(DirectoryPath + @"\" + fileName + ".pdf"); fileStream.Write((byte[])file.imgFileContent.ToArray(), 0, ((byte[])file.imgFileContent.ToArray()).Length); fileStream.Close(); }