Saving MailMerge Document into SQL Database


#1

I have an ASPOSE.Word Document that I want to save into a SQL Server Table but I get this error.

Message "Object must implement IConvertible." String
StackTrace " at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoUpdateDataSet(UpdateBehavior behavior, IDbConnection connection, DataSet dataSet, String tableName, DBCommandWrapper insertCommand, DBCommandWrapper updateCommand, DBCommandWrapper deleteCommand)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.UpdateDataSet(DataSet dataSet, String tableName, DBCommandWrapper insertCommand, DBCommandWrapper updateCommand, DBCommandWrapper deleteCommand, UpdateBehavior updateBehavior)
at MailMerge.Data.UpdateMailMergeDocuments(Int32 RequestID, Document doc, String FormatType, String DocumentType, String DocumentName, DateTime FileDateModified) in C:\Inetpub\wwwroot\MailMerge\Data.vb:line 162" String

I looked up this error and it seems to be complaining that the document is not a byte array. How can I convert this ASPOSE.Word Document into a Byte Array?


#2

You are able to convert a Document to a byte array with the following code. _doc is the Aspose.Word.Document instance.

// Create a new MemoryStream and save the document to that stream
MemoryStream msStream = new MemoryStream();
myAsposeDoc.Save(msStream, SaveFormat.FormatDocument);

// Return the MemoryStream as byte Array
return msStream.ToArray();

cheers tinu