Click here to Skip to main content
15,664,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please I use the code to upload pdf file into the database, it works perfect, I need help on how to retrieve the pdf file into a testbox.

Dim fInfo As New FileInfo(txtcv.Text)
        Dim numBytes As Long = fInfo.Length
        Dim fStream As New FileStream(txtcv.Text, FileMode.Open, FileAccess.Read)
        Dim br As New BinaryReader(fStream)
        Dim data As Byte() = br.ReadBytes(CInt(numBytes))

       cmd.Parameters.AddWithValue("@CV", data)

What I have tried:

If sdr.HasRows Then
          While sdr.Read()
              If sdr("CV") IsNot System.DBNull.Value Then
                  Dim data As Byte() = DirectCast(sdr("CV"), Byte())
                  Dim ms As New MemoryStream(data)
         = IO.File.ReadAllBytes(data)
              End If

          End While

      End If

but its not working
Updated 17-Aug-17 3:03am
OriginalGriff 17-Aug-17 7:52am    
"It's not working" is one of the most useless problem descriptions we get: it tells us absolutely nothing about the problem. We don;t know if you get an error message, or the wrong data, or even that that code compiles successfully!
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So tell us what happens when you run that code, what you expected to happen, how you checked what happened. Help us to help you!
Use the "Improve question" widget to edit your question and provide better information.
ZurdoDev 17-Aug-17 8:10am    
A textbox cannot display a pdf like that. You need a pdf reader.
Graeme_Grant 17-Aug-17 8:59am    
Not working? how is it not working??? As mentioned above, please improve your question and include the line with the error + the actual error thrown...

Also, the title of question needs to be updated to something like "How to display PDF from a memory stream in xxxx" where xxx is the platform that you are using... eg: WinForm, WPF, ASP.NET, MVC, Xamarin, etc...

1 solution

Taking a wild stab at what you are asking, this may be what you are looking for:

This Google Search: display pdf in winform app[^]

Found this: Viewing PDF in winforms[^]

And this Google Search: memorystream to pdf - Google Search[^]

Found this: Convert a byte array to pdf in c#[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900