George M
George M

Reputation: 83

Retrieve image stored in in db and save to a file

I have a customer that is asking to be able to retrieve an image from a Sql Server Db and turn around and save it to a directory on his computer. He wants to be able to do this via a asp.net web page. I am able to retrieve the image from the image as a byte array but have no idea how to take that image and save it to the directory as a file. Anyone have any ideas on how to do this? Thanks.

Upvotes: 0

Views: 911

Answers (1)

Aghilas Yakoub
Aghilas Yakoub

Reputation: 29000

You can try with Save Method

    MemoryStream memoryStream = new MemoryStream((byte[])YourDataTable.Rows[0]["ImageData"]);
    Picturebox picturebox = new Picturebox();
    picturebox.Image = Image.FromStream(memoryStream);
    picturebox.Image.Save("...YourPath", System.Drawing.Imaging.ImageFormat.Jpeg)

Upvotes: 1

Related Questions