Click here to Skip to main content
14,644,624 members
Rate this:
Please Sign up or sign in to vote.
See more:
**retrieve rtf text with images stored in sql database with windows form in web form with exactly " format and images " **

What I have tried:

code to stor in windows form

Dim cmd As New SqlCommand("UPDATE questions SET ques_rich = @ques_rich WHERE quest_no = 1 ", con)


cmd.Parameters.AddWithValue("@ques_rich", RichTextBox1.Rtf)


code to retrieve in

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New SqlConnection("Data Source=AHMEDHASHEM\SQLEXPRESS;Initial Catalog=test;Integrated Security=True")
Dim cmd1 As New SqlClient.SqlCommand
Dim tbl As New DataTable
Dim reader As SqlClient.SqlDataReader
Dim sql As String
sql = "select * from questions where quest_no = 1"
cmd1 = New SqlClient.SqlCommand(sql, con)
Dim ds1 As New DataSet()
Dim Adpt1 As New SqlDataAdapter(sql, con)
Adpt1.Fill(ds1, "questions")
'rc = ds1.Tables(0).Rows.Count


tbxTinymce.Text = ds1.Tables("questions").Rows(0)("ques_rich")
End Sub
note : i use tinymce and freetextbox controle

also use word document with this code

Dim wordApp As New Microsoft.Office.Interop.Word.ApplicationClass()

Dim nullobj As Object = System.Reflection.Missing.Value

Dim doc As Word.Document = wordApp.Documents.Open("c:\goinstall.doc")

Dim doc1 As Word.Document = wordApp.ActiveDocument

Dim m_Content As String = doc1.Content.Text

FreeTextBox1.Text = m_Content

doc.Close(nullobj, nullobj, nullobj)
that code retrieve text only without images and formatting
Updated 30-Apr-17 5:46am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Yeah, this is not so simple. YOu're NOT going to get a perfect reproduction of the RTF document in HTML. RFT is not HTML. HTML does not behave the same way as RTF.

Another problem. You cannot use Office Interop in a web application. It'll work on your DEV machine but fail when you deploy it to a web server. Office is not supported in a non-interactive (i.e.: server app on a non-interactive desktop) environment.

In an RTF document, the images are encoded and embedded in the document itself. HTML doesn't work that way. Well, not practically anyway as this will bloat the HTML massively.

There are converters on the web that will say "Convert RTF to HTML!", but they usually only work with font formatted text, like italic and bold, some even handle simple tables. I don't know of one that handles images.

But, in all cases, you get an HTML version of the RTF document, which does NOT behave or render exactly the same as the RTF document.
ahmed_hashem 30-Apr-17 11:52am
Thanx dave for comment ; but i alredy store rtf in database in windows application and i try to creat web application use this database
I am sorry for my poor english
Dave Kreskowiak 30-Apr-17 15:33pm
Yeah, that doesn't say anything that you haven't already said.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100