Write PDF or Word Document from Byte Array To Memory Stream

Once you store a Word Document or PDF Document in your database as a BLOB you then need to convert it to a Byte Array in order for the browse to launch Word or Adobe to open the PDF. This example pulls either the Word or PDF version from a table. 

//Select either the Word or PDF version
byte[] ProposalDoc;
string ContentType = string.Empty;
string Extension = string.Empty;

if (asWord)
    ProposalDoc = row.PROPOSAL_WORD;
    ContentType = "application/word";
    Extension = ".doc";
    ProposalDoc = row.PROPOSAL_PDF;
    ContentType = "application/pdf";
    Extension = ".pdf";

MemoryStream MemStream = new MemoryStream(ProposalDoc);
CTX.Response.ContentType = ContentType;
       "attachment; filename=" + DocumentName + Extension);
//Response.AddHeader("Content-Length", oStream.Length.ToString());

CTX.Response.Buffer = true;

Save APSOSE Document to PDF or Word save to Memory Stream

The ASPOSE document object is not searializeable.  In order to save the object to the database you first have to convert it to a memory from the object (such as PDF of Word). Once you have it in a Byte Array you can updated a BLOB column in the database.

//Convert to WORD
MemoryStream outStream = new MemoryStream();
asposeDocument.Save(outStream, Aspose.Words.SaveFormat.Doc);
byte[] docBytes = outStream.ToArray();

//Convert to PDF
outStream = new MemoryStream();
asposeDocument.Save(outStream, Aspose.Words.SaveFormat.Pdf);
byte[] pdfBytes = outStream.ToArray();