I am trying to merge to byte arrays and can't seem to get my code to work. Code below. Can i get some thoughts on what might be happening? I have verified that the arrays DO have data in them(aka length > 0).
Dim pdfBytesSyllabus AsByte() = pdf.GetPdfBytesFromHtmlStream(streamSyllabus, System.Text.Encoding.ASCII)
Dim pdfBytesCenter AsByte() = pdf.GetPdfBytesFromHtmlStream(streamCenter, System.Text.Encoding.ASCII)
Array.Copy(pdfBytesCenter, 0, pdfBytesSyllabus, pdfBytesSyllabus.Length, pdfBytesCenter.Length)
Array.Copy won't work as it does not resize the destination array (pdfBytesSyllabus) to hold the additional data from pdfBytesCenter.
The steps required are
1) Create a new array of sufficient length to hold both arrays
2) Copy pdfBytesSyllabus to the new array at index 0
3) Copy pdfBytesCenter to the new array at index pdfBytesSyllabus.Length
Much the same thing could be done with a generic List Of Byte, which is really just an implementation of a resizable array with a lot of useful methods added.
As Alan has said, the problem is to do with the fact that the array isn't big enough to contain this. A simple way to fix this is to create a generic list of bytes and add the data into it. You can easily get an array out of this like this:
Dim pdfData AsNew List(Of [Byte])(pdfBytesSyllabus.Length + pdfBytesCenter.Length)
' To get an array, just use
Dim cumulativePdfData AsByte() = pdfData.ToArray()
I was brought up to respect my elders. I don't respect many people nowadays.