Hi,
My code saves a Aspose.Word document to a MemoryStream, converts the stream to a Byte Array and then stores it in the database. Later, the user downloads the file, which performs the opposite: Database > Byte Array > Streamed to browser.
My problem: When they open the downloaded document, it’s corrupted. See attached file.
Here’s the code I use to save the document and convert it to a Memory Array. Note that if I save it to disk, it works fine:
Dim stream As New IO.MemoryStream
bodyDoc.Save(stream, Aspose.Words.SaveFormat.Doc)
'convert stream to byte array...
Dim length As Integer = stream.Length
Dim bytes(length) As Byte
stream.Read(bytes, 0, length)
'store in DB
Dim taFile As New Business.FileManagement.dsFileStoreTableAdapters.taQueries
Dim File_Id As Integer = CInt(taFile.InsertFileTransit(FileName, length, "application/msword", bytes, CurrentUser.AuditName))
Here's the code I use to download the document:
Dim si As New ServiceInterface.FileManagementSI
Dim dt As DataStructures.dsFileStore.FileDataTable = si.GetFile(File_Id)
Dim dr As DataStructures.dsFileStore.FileRow = dt(0)
Dim Response As System.Web.HttpResponse = HttpContext.Current.Response
Response.ClearContent()
Response.AppendHeader("content-length", result.Length.ToString())
Response.AppendHeader("content-disposition", String.Format("attachment;filename={0}", dr.filename))
Response.ContentType = dr.ContentType
Response.BinaryWrite(result)
Response.Flush()
Response.Close()