This is a migrated thread and some comments may be shown as answers.

saving/retrieving rtf from database

3 Answers 342 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Xavier
Top achievements
Rank 1
Xavier asked on 01 Nov 2011, 01:41 PM
Hello,

I'd like to load ans save a rtf file from my sql server database....
When I was in Winforms, I had the "rtf" members from the RichTextBox that was helpful.
How could I achieve this with the RadRichTextBox ?

Best Regards
Xavier

3 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 04 Nov 2011, 08:50 AM
Hi Xavier,
You can find more info in the help sections for format providers and data providers.

Kind regards,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Xavier
Top achievements
Rank 1
answered on 14 Nov 2011, 06:47 PM

 

Thanks, it helped me, but I’m still not able to do what I want....

I’d like to store the rtf file in a database field (Nvarchar(max)). So, I created a RtfFormatProvider, but all I can do is import/export as string and not as a file (radRichTextBox1.Document = d.Import(myField) & myfield = d.Export(radRichTextBox1.Document)).

 

How can I import/export from/to my database as a rtf file ? The Export and Import have a stream parameter, but where does this stream come from ?

Thank you for any advice.

Xavier

0
Iva Toteva
Telerik team
answered on 16 Nov 2011, 04:56 PM
Hello Xavier,

As described in the article on format providers that Boby quoted for reference, most format providers have overload methods for import and export from/to stream, byte[] and string. This is also the case with RtfFormatProvider. In short, you can import and export the content of a document using a stream in the following way:

RtfFormatProvider provider = new RtfFormatProvider();
provider.Export(editor.Document, stream);
this.editor.Document = provider.Import(stream);

The stream can be a MemoryStream you have created, the Stream of a SaveFileDialog (in that case the content of the document is written to the file chosen in the SaveFileDialog) or any other stream you have writing permissions to.

However, when it comes to saving the content of a document in a database, what you really need is the string result of the export of the document. After having exported the document to a string, you can use this string to fill the field in the database.

All the best,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Xavier
Top achievements
Rank 1
Answers by
Boby
Telerik team
Xavier
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or