Please check out this code for retrieving the image from the sql server, first get the image field data in a data reader and from there we can convert the data into a BYTE array, using that array the file can be created..
have a look
byte[] file = SqlConvert.ToByteArray(dr["FileImage"]);
string fileName = SetupFileName(SqlConvert.ToString(dr["FileName"]));
string filePath = System.Environment.CurrentDirectory + “\\myFiles\\” + fileName;
FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(file);
bw.Flush();
bw.Close();
fs.Close();
string fileName = SetupFileName(SqlConvert.ToString(dr["FileName"]));
string filePath = System.Environment.CurrentDirectory + “\\myFiles\\” + fileName;
FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(file);
bw.Flush();
bw.Close();
fs.Close();
Happy Coding!!!! :)
ThanksAnil Kumar PandeySystem ArchitectGreen Point Technology (India) Ltd.Mumbai, Maharshtra
INDIA
No comments:
Post a Comment