Hi,
I have many images in a database and I need to save them to an image file before I show them in a web page.
Can anyone tell me how this is done?
Thanks,
Saving an image to file.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Lee27 reputationPosted Jan 12, 2006, 1:07 AM EST
[CODE]
if(!File.Exists(dsBericht.Tables[0].Rows[0]["strImagePicName"].ToString()))
{
baImage = (byte[])dsBericht.Tables[0].Rows[0]["imgImagePic"];
try
{
sFileName =
dsBericht.Tables[0].Rows[0]["strImagePicName"].ToString();
if(sFileName.IndexOf("wwwroot")<=0)
{
sFilePath = sPath + sFileName;
}
else
{
int iWeg = sFileName.LastIndexOf("\\");
sFileName = sFileName.Substring(iWeg, sFileName.Length - iWeg);
sFilePath = sPath + sFileName;
}
FileStream fs = new FileStream(sFilePath, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(baImage);
bw.Close();
fs.Close();
}
catch(Exception ex)
{
string sError = ex.Message;
}
}
[/CODE]