I am using this function to convert the contents of my richtextbox to html:

Public Function myRTF_To_HTML(ByVal sRTF As String) As String

        Dim MyWord As Microsoft.Office.Interop.Word.Application
        Dim oDoNotSaveChanges As Object = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges
        Dim sReturnString As String = ""
        Dim sConvertedString As String = ""
        Try
            MyWord = CreateObject("Word.application")
            MyWord.Visible = False
            MyWord.Documents.Add()


            Dim doRTF As New System.Windows.Forms.DataObject
            doRTF.SetData("Rich Text Format", sRTF)
            Clipboard.SetDataObject(doRTF)
            MyWord.Windows(1).Selection.Paste()
            MyWord.Windows(1).Selection.WholeStory()
            MyWord.Windows(1).Selection.Copy()
            sConvertedString = Clipboard.GetData(System.Windows.Forms.DataFormats.Html)
            'Remove some leading text that shows up in the email
            sConvertedString = sConvertedString.Substring(sConvertedString.IndexOf("<html"))
            'Also remove multiple  characters that somehow got inserted 
            sConvertedString = sConvertedString.Replace("Â", "")
            sReturnString = sConvertedString
            If Not MyWord Is Nothing Then
                MyWord.Quit(oDoNotSaveChanges)
                MyWord = Nothing
            End If
        Catch ex As Exception
            If Not MyWord Is Nothing Then
                MyWord.Quit(oDoNotSaveChanges)
                MyWord = Nothing
            End If
            MsgBox("Error converting Rich Text to HTML")
        End Try
        Return sReturnString
    End Function

It is doing its work properly with texts but when i insert an image and save the file in .htm format and open that HTML file, the images are not displayed. PLEASE SOLVE MY PROBLEM. Help !

hi,

If you do a view source can you see the <img> tags? If they are there, I suspect they are pointing to a local path relative to your word doc - If memory serves correctly when you save a word file to HTML it creates a folder to keep images etc in. However, depending on how Word embeds the image, they may not get converted across - I'm a bit rusty on this.

I googled this and found that Microsoft Word does have problems with images. It creates references to the image in some temp folder and is not able to display it in the browser.

Have you thought about using the richtextbox itself? You can load the file directly, and access the rtf code as well. If the picture is embedded the rtf code should show it as a string of bytes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.