We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Save document to database using .NET

Hello all, I’m new to Aspose.Words and working on a C# application where I’m attaching an Aspose.Words generated document to table field after generation, based on a template I made from scratch.

The only problem is the document is empty every time. I’ve used the GetMergeFields()-method and it finds my merge fields and populates them with the Execute()-method but when generated it shows absolutely nothing, not even plain text.

I’m sorry if this is too general a question but I appreciate any help. I will attach my template in this post.

/Per NäsströmTest Aspose template.docx.zip (13.9 KB)

Sorry, I had made a mistake!

I forgot to save the document to the stream before converting it to a byte array to save to the table field. This fixed it.

I’m sorry to turn this into a different question, but I don’t understand what I’m doing and why when I’m saving the document to a memory stream. To then save it to a byte array to save it to a database field. I understand to the extent that a database field cannot store something like a document in any other way. But I don’t understand why I need to save the document to a memory stream before converting the ‘stream’, not the document, into a byte array to store in a field.

Does anyone know better how this works?

Thanks for any help received.

/Per Näsström

@Per_Nasstrom

The Document.Save method saves the document to disk or stream. After saving the document, you can insert it into database. Your understanding about saving document to database is correct. For more detail, please read the following article.
Save a Document to Database