Appending Byte() to another Byte()

btisdabomb

Member
Joined
Jul 12, 2006
Messages
16
Programming Experience
Beginner
I have two byte() arrays

Dim result As Byte() = X
Dim result2 As Byte() = Y

I need to append result2 to result. How can I do that?

I essentially need...

result3 = result + result2
 
two ways to do it, the commented Redim statement is doing the same as Array.Resize:
VB.NET:
        Dim index As Integer = result.Length
        Array.Resize(result, result.Length + result2.Length)
        'ReDim Preserve result(result.Length + result2.Length - 1)
        result2.CopyTo(result, index)
VB.NET:
        Dim mem As New IO.MemoryStream
        mem.Write(result, 0, result.Length)
        mem.Write(result2, 0, result2.Length)
        result = mem.ToArray
btw, I just put everything into 'result' array, you'll manage to put it into a new third array instead if you wish.
 
Thanks for the help JohnH. This doesn't seem to be working though.

Result and Result2 are actually Microsoft Reporting Services Reports that are being returned as Byte Arrays.

My goal is to combine and output these two reports to html (or pdf) as one big report. I am outputing them using the following...

Dim stream As FileStream = File.Create("report.mht", result3.Length)
stream.Write(result3, 0, result3.Length)
stream.Close()

Each time I output the file, it ends up being only 1 of the reports. Even after I combine them using your methods or other methods that I have tried. Any ideas?
 
dude, that's like saying youre trying to create a word processor with spreadsheet facilities by appending the bytes of EXCEL.EXE onto the end of WINWORD.EXE - i cant really express how daft it sounds to me.
 
dude, that's like saying youre trying to create a word processor with spreadsheet facilities by appending the bytes of EXCEL.EXE onto the end of WINWORD.EXE - i cant really express how daft it sounds to me.

How is that? I have two Microsoft Reporting Service reports... I am trying to append them together. Microsoft Reporting Services allows you to export the results/reports in various formats such as HTML, PDF, EXCEL, etc...

I am getting two reports in HTML format and I want to append those together.

Reporting Services has a webservice that will return the reports to you based on paramters that you pass in. You specify what the format is, in this case HTML. It then returns a byte array of the report.

http://msdn2.microsoft.com/en-us/li...ervice2005.reportexecutionservice.render.aspx

result = rs.Render(format, devInfo, extension, _
encoding, mimeType, warnings, streamIDs)

I am getting two reports back result and result2 as Byte Arrays. I want to append these together and output them as one report.

Thanks for your comments cjard, but they weren't very helpful.
 
In the case of Html/plain text (byte) content this should have worked (kinda), for most other file formats the content reader application will either stop reading after first part or crash. IE is forgiveable for problematic html syntax (like putting multiple documents into one file) but will parse everything into one document tree, the body parts should be appended but there might be conflicting script or header content that makes such a "dead merge" unrenderable.
 
In the case of Html/plain text (byte) content this should have worked (kinda), for most other file formats the content reader application will either stop reading after first part or crash. IE is forgiveable for problematic html syntax (like putting multiple documents into one file) but will parse everything into one document tree, the body parts should be appended but there might be conflicting script or header content that makes such a "dead merge" unrenderable.

Thanks again for the help JohnH. Your code is in fact working (kinda). I completely overlooked the fact of conflicting sections in the html. If I output using a different format such as XML, it works as expected... although the XML isn't "well-formed".
 
I am getting two reports back result and result2 as Byte Arrays. I want to append these together and output them as one report.

Thanks for your comments cjard, but they weren't very helpful.

Just incase you missed the point I was trying to make, computing isnt like baking a cake. Programming doesnt just involve mixing things together.

An HTML file has a start and and end. Joining two together means you have a bigger file with an end and a start in the middle (your perspective) or one valid HTML file with a bunch of uninteresting trash after the end (computer's perspective).

As John says, you can hope that the viewer will parse your illegal HTML and show it anyway, or you can form it into a legal HTML document. If youre doing this with binary (as implied by your byte array references) you have a diminished chance because, though there isnt much conceptual difference betweena binary file and an html one (i.e. its just a bunch of data full of characters with special meanings) it isnt quite so human readable
 
Just incase you missed the point I was trying to make, computing isnt like baking a cake. Programming doesnt just involve mixing things together.

An HTML file has a start and and end. Joining two together means you have a bigger file with an end and a start in the middle (your perspective) or one valid HTML file with a bunch of uninteresting trash after the end (computer's perspective).

As John says, you can hope that the viewer will parse your illegal HTML and show it anyway, or you can form it into a legal HTML document. If youre doing this with binary (as implied by your byte array references) you have a diminished chance because, though there isnt much conceptual difference betweena binary file and an html one (i.e. its just a bunch of data full of characters with special meanings) it isnt quite so human readable

Thanks cjard, this post would have helped earlier. I was overlooking the fact that html has that start and end point. And that joining the two together will cause "illegal" html.

I'm not sure how that translates into trying to append bytes of excel.exe into winword.exe, but your point is now understood.
 
Back
Top