Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Imports System.Data.SqlClient
Imports System.IO
Module ModFiles
Function GetBLOB(ByVal Path As String) As Array
'Path: The path the file should be uploaded from, ie "C:\autoexec.bat"
Try
'TheFile is a FileStream that streams the file from it's original path
Dim TheFile As New FileStream(Path, FileMode.OpenOrCreate, FileAccess.Read)
'FileData is the data in the file.
Dim FileData(CInt(TheFile.Length)) As Byte
'Read the Data in the file
TheFile.Read(FileData, 0, CInt(TheFile.Length))
'Close the TheFile object
TheFile.Close()
'Return the file as a Blob to the calling procedure
GetBLOB = FileData
Catch ex As Exception
MessageBox.Show("Image Conversion Failed!" & ControlChars.CrLf & ex.ToString, "File conversion", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error)
Finally
End Try
End Function
Function UpdateBlob_TblLetters(ByVal TheBlob As Array, ByVal Path As String, ByVal LetterID As String) As Boolean
Dim cnn As New SqlConnection(SQL_Connection)
Dim cmd As New SqlCommand
'Try to update the record
Try
With cmd
.Connection = cnn
.CommandText = "modFiles_UpdateBlobLetterID_Upd"
.CommandType = CommandType.StoredProcedure
'Pass the LetterID that the template should be updated for.
.Parameters.Add("@LetterID", SqlDbType.VarChar, 6)
.Parameters("@LetterID").Direction = ParameterDirection.Input
.Parameters("@LetterID").Value = LetterID
'Pass the BLOB (file) object
.Parameters.Add("@TheBlob", SqlDbType.Image)
.Parameters("@TheBlob").Direction = ParameterDirection.Input
.Parameters("@TheBlob").Value = TheBlob
End With
cnn.Open()
'Perform the update on the server
cmd.ExecuteNonQuery()
cnn.Close()
MessageBox.Show("Successfully added the file to the template")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Function ExportBlob_TblLetters(ByVal Path As String, ByVal LetterID As String) As Boolean
Dim cnn As New SqlConnection(SQL_Connection)
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
'Dim da As New SqlDataAdapter("Select * From tbl_Letters Where LetterID = '" & LetterID & "'", cnn)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet
With cmd
.Connection = cnn
.CommandText = "modFiles_ExportBlobLetterID_Sel"
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@LetterID", SqlDbType.VarChar, 6)
.Parameters("@LetterID").Direction = ParameterDirection.Input
.Parameters("@LetterID").Value = LetterID
End With
da.SelectCommand = cmd
Try
cnn.Open()
da.Fill(ds, "TheFile")
Dim MyRow As DataRow
MyRow = ds.Tables("TheFile").Rows(0)
Dim FileData() As Byte
FileData = MyRow("Template")
Dim K As Long
K = UBound(FileData)
Dim fs As New FileStream _
(Path, FileMode.OpenOrCreate, _
FileAccess.Write)
fs.Write(FileData, 0, K)
fs.Close()
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
cnn.Close()
cnn = Nothing
MsgBox("Image retrieved")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
End Module