Extract images from sql server

F

Filip De Backer

Hi,

I've got a column in a table which contains images (bmp
and jpg, i guess sql server don't convent the jpg to
bmp??).

How can I extract these images from the table.
I've tried something with a MemoryStream, but I don't know
how to save it to a file because this stream is a byte
array and I can't check the file type and other stuff like
that.

Is there anybody with the same problem?

Thanks a lot

Filip
 
S

Sergey Ivasenko

........................
Type type = Table.Rows[0]["bitmap"].GetType();
System.Byte[] buf = Table.Rows[0]["bitmap"] as Byte[];

SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(buf);
bw.Close();
fs.Close();
}

..................................
This code worked in my case.

Best regards,
Sergey Ivasenko.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top