How can I write a byte array to a file using a SaveFileDialog

Good Morning Experts,
I need help Reading and Saving files and images stored as varbinary data in my database using SaveFileDialog in my VB.Net application.

I am able retrieve the data column from my SQL Server DB.  Now that I have the data, I want to save the data to a selected file path via SaveFileDialog.  How do I do this?

The varbinary data could be a .pdf, .tif, .jpg, or .docx.

This is the code I have so far.  What should I put inside the parenthesis of bw.Write()
 
    Private Sub btnRetrieve_Click(sender As System.Object, e As System.EventArgs) Handles btnRetrieve.Click
        Dim dta As New TestDBDataSetTableAdapters.sp_SelectFileTableAdapter
        Dim dt As TestDBDataSet.sp_SelectFileDataTable = dta.GetData(6)
        Dim file As String = "D:\temp\test.docx"

        Dim dr As DataRow
        For Each dr In dt.Rows
            WriteWordDoc(file, dr("FileData"))
        Next
    End Sub

    Private Sub WriteWordDoc(filename As String, data As Byte())
        Dim fs As New System.IO.FileStream(filename, IO.FileMode.Create)
        Dim bw As New System.IO.BinaryWriter(fs)
        bw.Write()
        bw.Close()
        fs.Close()
    End Sub

Open in new window


Thank you,
mrotor
mainrotorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard LeeSoftware EnthusiastCommented:
Put the byte array into the Write method.

bw.Write(data)

Open in new window


https://msdn.microsoft.com/en-us/library/system.io.binarywriter(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/bx149a0k(v=vs.110).aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.