[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I open a PDF Blob field in SQL Server and open the file using VB.Net?

Posted on 2014-01-13
7
Medium Priority
?
1,119 Views
Last Modified: 2014-01-14
I have a SQL Server table that contains a BLOB column (PDF files are stored in this column). I need to retrieve it using VB.Net and open it as a PDF File. Any ideas?

Thanks!
0
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 13

Expert Comment

by:ktaczala
ID: 39778208
Open it as a filesteam, write it to disk as "c:\temp\tmpfile.pdf" then run process.start("c:\temp\tmpfile.pdf") that will open the file with the default PDF app.
0
 
LVL 13

Expert Comment

by:ktaczala
ID: 39778239
A little more detail.

load the blob into a datatable:
get the image.length into a variable
get the # of bytes of the image.
read it into a memorystream
write it to a filestream
 then open with process.start

for example (this is a guide)
        If ImageDataGridView.Rows.Count = 0 Then 'no row exists
            Exit Sub
        End If

        Dim curimageID = row.ImageID
        currentImageID = curimageID
        Dim _dtImage As New DSDocuments.ImageDataTable
        Dim _taImage As New DSDocumentsTableAdapters.ImageTableAdapter
        Dim _drImage As DSDocuments.ImageRow
        Dim _intLength As Integer
        Dim _imageBytes() As Byte
        Try
            _taImage.FillImagesByImageID(_dtImage, curimageID)
            If _dtImage.Count > 0 Then
                _drImage = _dtImage.Rows(0)
                _intLength = _drImage.Image.Length
                _imageBytes = _drImage.Image     ' database value into bytes
                Dim _originalImageMemoryStream As New System.IO.MemoryStream(_imageBytes, 0, _imageBytes.Length) ' bytes --> stream
                If Not Directory.Exists(tempfilepath) Then
                    Directory.CreateDirectory(tempfilepath)
                End If
                If File.Exists(tempfilepath & "\temp" & tempincrement.ToString & fileextension) Then
                    Try
                        Dim _fs1 As FileStream = File.OpenWrite(tempfilepath & "\temp" & tempincrement.ToString & fileextension)
                        _fs1.Close()
                        File.Delete(tempfilepath & "\temp" & tempincrement.ToString & fileextension)
                    Catch ex As Exception
                        tempincrement += 1
                    End Try
                End If
                viewercurrentfilename = tempfilepath & "\temp" & tempincrement.ToString & fileextension
                Dim _fs As FileStream = File.OpenWrite(viewercurrentfilename)
                _originalImageMemoryStream.WriteTo(_fs)
                _fs.Close()
                            System.Diagnostics.Process.Start(viewercurrentfilename)
0
 

Author Comment

by:BlakeMcKenna
ID: 39779290
Ok, I tried what you suggested in your 1st post. However, I get an error saying:

"A required privilege is not held by the client".

What is that? I'm writing the file to my C: drive and I'm the administrator of my own machine. Never seen this one before.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Accepted Solution

by:
ktaczala earned 2000 total points
ID: 39779306
save it to an existing folder not in the root
0
 

Author Comment

by:BlakeMcKenna
ID: 39779320
That worked but why can't I save it to the root drive?
0
 
LVL 13

Expert Comment

by:ktaczala
ID: 39779343
Windows(microsoft) just don't want you to save there by default.
0
 

Author Comment

by:BlakeMcKenna
ID: 39779476
That works for me!

Thanks again!
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

649 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