Question : Open Blob Image from SQL in VB.Net

I am attempting to open a pdf file stored in sql image column. The code below works fine, except I have to specify a directory to save the file in. How can I just open the file, and give the user the Open/Save dialog box instead of specifying a directory?

 Dim da As New SqlDataAdapter _
                 ("Select * From docimages where doc_number = '" & MyDoc & "'", Con)
                Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
                Dim ds As New DataSet()

                Con.Open()
                da.Fill(ds, "docimages")
                Dim myRow As DataRow
                myRow = ds.Tables("docimages").Rows(0)

                Dim MyData() As Byte
                MyData = myRow("Image")
                Dim K As Long
                K = UBound(MyData)

                ' Dim fs As new FileStream(

               
                Dim fs As New FileStream _
                ("C:\Adode\test.pdf", FileMode.OpenOrCreate, FileAccess.Write)
                'fs.Read(MyData, 0, K)
                fs.Write(MyData, 0, K)
                fs.Close()

                fs = Nothing
                MyCB = Nothing
                ds = Nothing
                da = Nothing

                con.Close()
                con = Nothing
                MsgBox("Image retrieved")

Answer : Open Blob Image from SQL in VB.Net

Hi, occ_user.

This cannot be done with a rule.  Rules only fire when a message is received or after it's sent.  This requires a macro.  The macro is simple enough, but it will have to be deployed to every computer.  Outlook does not have an automated means of distributing macros.  Deploying the macro will have to be done manually.  The more computers there are in the organization the more of a pain this becomes.  Also, a savvy user could turn the macro off.

The above aside, here's the macro.  Follow these instructions to use it.

Outlook 2007
1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comment lines wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools > Trust Center
9.  Click Macro Security
10. Set Macro Security to "Warnings for all macros"
11. Click OK
12. Close Outlook
13. Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.


Outlook 2003 and Earlier
1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of
5.  Outlook's VB Editor window
6.  Edit the code as needed.  I included comment lines wherever something needs to or can change
7.  Click the diskette icon on the toolbar to save the changes
8.  Close the VB Editor
9.  Click Tools > Macro > Security
10. Set the Security Level to Medium
11. Close Outlook
12. Start Outlook
13. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.
1:
2:
3:
4:
5:
6:
7:
8:
9:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If Item.Class = olMail Then
        If InStr(1, Item.Subject, ":") Then
            'Edit the warning message and title on the next line as needed.'
            msgbox "The subject contains a colon.  Please remove it and then send again.", vbCritical + vbOKOnly, "Company Policy"
            Cancel = True
        End If
    End If
End Sub
Random Solutions  
 
programming4us programming4us