Free Support Forum -

Converting jpg to Byte


I have been successfully inserting images from a SQL database into Word documents for quite some time.

A new requirement has arisen where we now want to put signature images in the documents when they have been uploaded into the database. This also works but I have a problem when no signature file has been loaded into database.

What I would like to do here is insert a standard 'blank' image from a file rather than database. Below is the code I am currently using. Is what I am trying to do possible and if so - how?

Thanks in advance.


Public Function GetSignatureImage(ByVal CoachID As Integer) As Byte()

Dim strBrandImage As Byte()

Using myConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

Const SQL As String = "Select SignImage from DB WHERE ID = @ID"

Dim myCommand As New SqlCommand(SQL, myConnection)

myCommand.Parameters.AddWithValue("@ID", ID)


Dim myReader As SqlDataReader = myCommand.ExecuteReader

If myReader.Read Then

If (myReader("SignImage")) Is System.DBNull.Value Then

strBrandImage = Nothing


strBrandImage = (myReader("SignImage"))

End If

End If

If strBrandImage Is Nothing Then

'Get image from a file and convert to byte - this is my problem

End If



End Using

Return strBrandImage

End Function


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can use the following code to get file bytes:

byte[] imageBytes = File.ReadAllBytes(@"C:\Temp\test.jpg");

Hope this helps.

Best regards.