|
Friends,
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 As Byte() = pdf.GetPdfBytesFromHtmlStream(streamSyllabus, System.Text.Encoding.ASCII)
Dim pdfBytesCenter As Byte() = pdf.GetPdfBytesFromHtmlStream(streamCenter, System.Text.Encoding.ASCII)
Array.Copy(pdfBytesCenter, 0, pdfBytesSyllabus, pdfBytesSyllabus.Length, pdfBytesCenter.Length)
Eric
|
|
|
|
|
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.
|
|
|
|
|
|
Uhhh...no. Alan nailed the problem exactly. You're just guessing at it.
|
|
|
|
|
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 As New List(Of [Byte])(pdfBytesSyllabus.Length + pdfBytesCenter.Length)
pdfData.AddRange(pdfBytesCenter)
pdfData.AddRange(pdfBytesSyllabus)
Dim cumulativePdfData As Byte() = pdfData.ToArray()
|
|
|
|
|
Thanks Alan/Pete,
Code worked great!
Eric
|
|
|
|
|