I create a PDF and save it in my database in the form of a byte[] through the use of a webservice. I then load the byte[] and generate a PDF. A new window opens but I get a message from Acrobat Reader saying the PDF could not be read correctly. I am not sure if the mistake lies in saving the PDF as a byte[] or in reading it....

This is how I save the PDF as byte[]:
Code:
        protected void ConvertPDFToByteArray()
        {
            try
            {
                string path = Server.MapPath("~/pdf/test.pdf");
                string path2 = Server.MapPath("~/pdf/byte.pdf");

                //This code reads in a pdf, then saves it with a different file name.
                fileArray = File.ReadAllBytes(path);
                File.WriteAllBytes(path2, fileArray);

                // Save Byte[] to db through webservice
                SetArchive();
            }
            catch (Exception e)
            {
                SData.tCurrentError = e.GetType();
                Response.Redirect("Error.aspx", true);
            }
        }
This is how I read the byte[] from the webservice:

Code:
 protected void GenerateArchivePDF(int value)
        {
            GetReport(selectedReportID); 

             // Create PDF on current path with doc name "test.pdf"
            string PDFpath = Server.MapPath("~/pdf/ArchivBeurteilungsbogen.pdf");

            using (stream = new FileStream(PDFpath, FileMode.Create))
            {
                  buffer = archive.PDFBitArray;

                  Response.Clear();
                  Response.ClearContent();
                  Response.ClearHeaders();
                  Response.ContentType = "application/pdf";
                  Response.AddHeader("Content-Disposition", "attachment;filename=/pdf/ArchivBeurteilungsbogen.pdf");
                  Response.AddHeader("Content-Length", buffer.Length.ToString());
                  Response.OutputStream.Write(buffer, 0, buffer.Length);
                  //Response.BinaryWrite(buffer);
                  Response.Flush();
                  Response.End();

                  // To open in a new window: by saving pdf first
                  Response.Write("<script type='text/javascript'>");
                  Response.Write("window.open('/pdf/ArchivBeurteilungsbogen.pdf','_blank')");
                  Response.Write("</script>");
              }
        }
Can you see any mistakes?