0

I am trying to append the multiple files into single file using bytes array but when i try to append the file it converts only single file which is last one. i use below code:

            byte[] outputBytes = new byte[0];
            byte[] temp1 = System.IO.File.ReadAllBytes(@"D:\2.doc");
            byte[] temp2 = System.IO.File.ReadAllBytes(@"D:\3.doc");

            outputBytes = new byte[temp1.Length + temp2.Length];
            Buffer.BlockCopy(temp1,0,outputBytes,0,temp1.Length * sizeof(byte));
            Buffer.BlockCopy(temp2,0,outputBytes,0,temp2.Length  * sizeof(byte));
            System.IO.File.WriteAllBytes(@"D:\myOutPut.doc",outputBytes);

i am creating one output file in which all files content is display.

Thank You.

Mitesh Machhi
  • 203
  • 2
  • 5
  • 18
  • 1
    Possible duplicate of [Combine multiple files into single file](http://stackoverflow.com/questions/14524909/combine-multiple-files-into-single-file) – Liam Mar 30 '17 at 14:28
  • or [Efficient way to combine multiple text files](http://stackoverflow.com/questions/444309/what-would-be-the-fastest-way-to-concatenate-three-files-in-c) or a couple of other answers. You should of googled this first. – Liam Mar 30 '17 at 14:29
  • hey @liam, i try your link but does not success. it convert only one word file. – Mitesh Machhi Mar 30 '17 at 14:43

1 Answers1

0

You need to set the dstOffset with the second BlockCopy

Buffer.BlockCopy(temp1, 0, outputBytes, 0, temp1.Length * sizeof(byte));
Buffer.BlockCopy(temp2, 0, outputBytes, temp1.Length, temp2.Length * sizeof(byte));

But I think you cannot concat doc files with this.

PinBack
  • 2,499
  • 12
  • 16