0

I am getting an error:

Value of type 'System.IO.FileStream' cannot be converted to '1-dimensional array of Byte'.

My code block is:

Dim FileToSign As System.IO.FileStream = GetTestPdfFile(fileName)
Dim SignedFileInfo As New secure.echosign.com.FileInfo()
SignedFileInfo.fileName = fileName
SignedFileInfo.mimeType = Nothing
SignedFileInfo.file = FileToSign

SignedFileInfo.file is a Byte type.
How can I convert File to byte?

user3929962
  • 517
  • 3
  • 6
  • 23

1 Answers1

1

If fileName is the name of your PDF file, and GetTestPdfFile isn't doing anything to the PDF file, you can instead use File.ReadAllBytes to get the file contents as a byte array:

SignedFileInfo.file = System.IO.File.ReadAllBytes(fileName)

If GetTestPdfFile is doing something other than returning a FileStream then you will need to use the FileStream.Read method to read the contents into a byte array:

Dim pdfLength As Integer = CInt(FileToSign.Length - 1)
Dim pdfBytes(pdfLength) As Byte
If FileToSign.Read(pdfBytes, 0, pdfLength) <> pdfLength Then
    ' Hmm, something's not right
End If
SignedFileInfo.file = pdfBytes

All code untested, but should be pretty close!

Mark
  • 8,140
  • 1
  • 14
  • 29