Sat Jan 19, 2013 9:39 am
Hello. I recently purchased and upgraded to Spire.Doc 4.6 (+ 4.6.9 hot fix) for Developer Pro Edition. I have a doc/docx stored as a varbinary(max) in an SQL2005/SQL2008 database table column. I can get the data from the column and load to a Spire.Doc.Document in some cases but in others I receive a "A disk error occurred during a write operation. (Exception from HRESULT:0X8003001D (STG_E_WRITEFAULT)) error. I have attached code I am using. It seems that small doc/docx files work correctly but not larger ones (>99KB). Please advise asap. Here is code being used.
If thisDocument._FileContent IsNot Nothing Then
Dim tempFileNamePDF As String
Dim spireFormat As FileFormat
If thisDocument._DiskFileName.Contains(".docx") Then
tempFileNamePDF = thisDocument._DiskFileName.Replace(".docx", ".pdf")
spireFormat = FileFormat.Docx
Else
tempFileNamePDF = thisDocument._DiskFileName.Replace(".doc", ".pdf")
spireFormat = FileFormat.Doc
End If
Dim ms As New MemoryStream()
Dim bw As New BinaryWriter(ms)
bw.Write(thisDocument._FileContent)
bw.Flush()
'Load the temp file into a Word Document object
Dim doc As Document = New Document(ms, spireFormat) <---- Exception occurs here !!!
'Create a new memorystream to hold the pdf and populate it (convert word to pdf here)
Dim pdfMS As New MemoryStream()
doc.SaveToStream(pdfMS, FileFormat.PDF)
doc.Close()
'Write pdf memory stream to byte array for delivery in the response
Dim pdfBytes As Byte()
pdfBytes = pdfMS.ToArray()
pdfMS.Close()
'Clear the content of the response
Response.ClearContent()
Response.ClearHeaders()
'Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
'Response.AddHeader("Content-Disposition", "attachment; filename=" + tempFileNamePDF.Replace(userNameMashUp, ""))
Response.AddHeader("Content-Disposition", "attachment; filename=" + tempFileNamePDF)
'Add the file size into the response header
Response.AddHeader("Content-Length", pdfBytes.Length.ToString())
'Set the ContentType as saved in database
Response.ContentType = "application/pdf"
'Write the file into the response
Response.BinaryWrite(pdfBytes)
'End the response
Response.End()
Else
Session("ErrorMessage") = "Error from DocumentList: The document " & fileName & " could not be retrieved from the database."
Throw New Exception("Error from DocumentList: The document " & fileName & " could not be retrieved from the database.")
End If