Solved

image field in sql database convert to actual files

Posted on 2011-03-22
5
239 Views
Last Modified: 2012-05-11
I have a bunch of binary data in my database in a image fields... I want to convert the binary files to
ACTUAL FILES  that i can save in a folder... can somebody tell me how to do this?

I will do this where datareader is the image field

 Do while
    dr("imagefield") 'DO SOMETHING
loop



0
Comment
Question by:vbnetcoder
  • 3
  • 2
5 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Unless I'm way off, the data should be coming back as a byte array [ Byte() ]. You could load that into a Stream for writing (this is an overview; you'll need to tweak it):
Do While
    Using ms As New System.IO.MemoryStream(DirectCast(dr("imagefield"), Byte()))
        Using img As Image = Image.FromStream(ms)
            img.Save("someFilename.someExt")
        End Using
    End Using
Loop

Open in new window

0
 

Author Comment

by:vbnetcoder
Comment Utility
That worked, Thank you!  Can you tell how I can tell for sure that there is a image?  Some fields may return as null.

Thank you
0
 

Author Comment

by:vbnetcoder
Comment Utility
Never mind i got it
0
 

Author Closing Comment

by:vbnetcoder
Comment Utility
ty
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
NP. Glad to help  = )
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now