How to loop through System.Byte[], which is a datarow?

I have datatable coming from SAP and each row is a System.byte[ ].
In the debug mode - I can see all the 1024 bytes, but how can I write it or view or loop through byte array.

You could just use a For Each activity and set the TypeArgument property to System.Byte.

For each Datarow → If I print the content of datarow, the output is: “System.Byte”. I want to convert this data, so that I can see it.
How can I pass this row(0).ToString to bytes ? - how do i read array of bytes from datarow?

Hi,

What style do you need? One of the simplest ways is to use BitConverter as the following.

img20220421-1

Regards,

This is how the datatable is coming:

image

How can I read the bytes from each row?
My final result is to convert as a pdf.

Hi,

For now, can you try as the following?

img20220421-5

Regards,

Hi,

I’ve tried it and looks like - I can see those values, but I think it is converting from Binary to Hexa format.
Example: 60 (binary) = 3C (hex)

Hi,

Can you share sample for input and expected output?

Regards,

Hi,

I’m sorry that I cannot share the data due to confidentiality. But your suggestion “BitConverter”, looks like its giving some direction for me.
I’ll give a try with it and see if it helps me out.

Thanks for you help!!

Hi,

FYI, hope the following also helps you.

arrByte = CType(row("LINE"),byte())

Let’s say arrByte={65,13}

Then

String.Join(",",arrByte)

returns

"65,13"

String.Join(",",arrByte.Select(Function(b) b.ToString("X")))

returns

"41,D"

Regards,

Hi ,

One last thing:
I’m able to save byte array as a pdf but when I open it, the file is corrupted. If I open the file in word, I can see the content.

Hi,

How did you create the pdf file?

Regards,

Hi,

image

Where pdfByte is byte array

Hi,

What is content of pdfByte? Is this binary data of pdf format like %PDF-1.3....?

Regards,

Hi,

Content in the byte array goes like this: [60, 33, 45, 45, …]

Hi,

We need to create pdf-binary format in advance if write it to the file directly.
If you already have expected word file, SaveDocumentasPDF activity will help you.

img20220421-6

Regards,

Hi,

So using this byte array, how can i convert to pdf?

Hi,

If your byte array is not pdf-binary format, you need to use library or application to create pdf. As Excel and Word have the function, we can create pdf using them easily.

Regards,

Thanks for your suggestions @Yoichi

I resolved it by opening the corrupted file in word application scope and then again used save document as pdf. It is working now.

1 Like

The complete solution for handling this type of scenario is to:

  1. For each datarow in dt_Input
    1.1. byteArray_arr1 = CType(row(“ColumnName”),byte())
    1.2. Loop through “byteArray_arr1” as each byte
    1.2.1. Add to a list_bytes (List)
  2. Repeat step 1 for all rows and all bytes
  3. Assign byteArray_arr1 = list_bytes.ToArray()
  4. Write all bytes as pdf
  5. If step 4 gives a corrupt pdf, try
    5.1. Opening the corrupted file in word application scope and then again used save document as pdf.