I am tryinf concatenate all the memory steams into single pdf, But If there is any one file is correpted all thye files are not concatenating.I am getting 0 KB.How to catch the corrupted file and skip that file.
Please help me on this ASAP.
Here is my code .
//create two file streams to read pdf files
FileStream fs1 = new FileStream(@“C:\Siddarth\P07\text-Copy.pdf”, FileMode.Open, FileAccess.Read);
FileStream fs2 = new FileStream(@“C:\Siddarth\P07\text-Copy.pdf”, FileMode.Open, FileAccess.Read);
//create byte arrays to keep the contents of PDF files
byte buffer1 = new byte[Convert.ToInt32(fs1.Length)];
byte buffer2 = new byte[Convert.ToInt32(fs2.Length)];
int i = 0;
//read PDF file contents into byte arrays
i = fs1.Read(buffer1, 0, Convert.ToInt32(fs1.Length));
i = fs2.Read(buffer2, 0, Convert.ToInt32(fs2.Length));
//now, first convert byte arrays into MemoryStreams and then concatenate those streams
using (MemoryStream pdfStream = new MemoryStream())
using (MemoryStream fileStream1 = new MemoryStream(buffer1))
using (MemoryStream fileStream2 = new MemoryStream(buffer2))
//create instance of PdfFileEditor class to concatenate streams
PdfFileEditor pdfEditor = new PdfFileEditor();
//concatenate both input MemoryStreams and save to putput MemoryStream
pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream);
//convert MemoryStream back to byte array
byte data = pdfStream.ToArray();
//create a FileStream to save the output PDF file
FileStream output = new FileStream(@“C:\Siddarth\P07\merged_output.pdf”, FileMode.Create,
//write byte array contents in the output file stream
output.Write(data, 0, data.Length);
//close output file
//close input files
In the above code I have multiple streams.While concatenate i am getting 0 KB in out put.
I just came to know that there is one pdf file got corrupted.How to catch corrupted file and skip rees of the memory streams.