Hi Aspose.
I’m using Aspose.Word to import data from MS-Word file to my database and binding to richtextbox.
In code behind:
Dim doc As New Document(OpenFile.FileName)
Dim table As Tables.Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Tables.Table)
Dim oResultDoc As New Document()
Dim outNode As Node = TryCast(oResultDoc.LastSection.Body.LastParagraph, Node)
Dim outCompositeNode As CompositeNode = oResultDoc.LastSection.Body.LastParagraph.ParentNode
Dim importer As New NodeImporter(doc, oResultDoc, ImportFormatMode.KeepSourceFormatting)
For Each srcNode As Node In table.Rows(1).Cells(0)
Dim newNode As Node = importer.ImportNode(srcNode, True)
outCompositeNode.InsertAfter(newNode, outNode)
outNode = newNode
Next
Dim oRichtextbox As New RichTextBox
oRichtextbox.Rtf = GetRtfString(oResultDoc, SaveFormat.Rtf)
Private Function GetRtfString(ByVal doc As Aspose.Words.Document, ByVal format As SaveFormat) As String
’ Save document to stream as RTF (you can save it also in HTML for example).
Dim rtfStream As New MemoryStream()
Dim options As SaveOptions = SaveOptions.CreateSaveOptions(format)
options.PrettyFormat = True
doc.Save(rtfStream, options)
’ Get string from stream.
Return Encoding.UTF8.GetString(rtfStream.GetBuffer())
End Function
If .doc file contain only text, the richtextbox work fine, but when .doc file contain image and also text, the richtextbox display text, not image. What is wrong in my code behind?
In the File attachment is my sample .doc file.
Hi Nga,
Thanks for your query. I have tested the scenario and have not found any issue while using latest version of Aspose.Words for .NET. Please use the latest version of Aspose.Words for .NET. Please see the image file in attachment.
Please let us know if you have any more queries.