Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1220
  • Last Modified:

VB.net Save image from memory stream

How do I modify the following code to rather save the image as an image file on my hard drive

             Dim oID As String = D.Rows(r).Cells(1).Value
                                Dim sSQL As String = "Select Photo from Photos where ID = " & oID & ""
                                Dim cmd2 As New SqlCommand(sSQL, con)
                                Dim ImgStream As New IO.MemoryStream(CType(cmd2.ExecuteScalar, Byte()))
                                PictureBox1.Image = System.Drawing.Image.FromStream(ImgStream)
0
Murray Brown
Asked:
Murray Brown
  • 2
1 Solution
 
Fernando SotoCommented:
Hi murbro;

This should work for you.

'' Where locationToSaveTo is a string with the path and filename on the disk.
System.IO.File.WriteAllBytes(locationToSaveTo, CType(cmd2.ExecuteScalar, Byte()));
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0
 
Fernando SotoCommented:
Not a problem, glad I was Ble to help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now