Is it possible to save the rich text?

Jun 10, 2008 at 9:22 AM
Hello,
I'm looking for a rich text editor for Silverlight. I want to thank you for your awesome rich editor. It's really the one I need.

I'm using Silverlight 2 Beta 1. I downloaded your editor project (r1.1) and I'm looking for a way to save and load the content of the rich text.
For instant, I want to save a paragraph which includes mixing text and some textbox with text content in (for example, saving to Xml) & load this paragraph into xaml page.
Is it possible to do that? Could you please give me some directions to archive this?

I'm looking in the documentation but I'm not sure the SnapShot class can help...

Thank you.
Coordinator
Jun 10, 2008 at 1:08 PM
Thanks for your interest!

The first thing to mention is that you should use Silverlight 2 Beta 2 which is out now, because it bring extensive changes and will proably break your code developed in Beta 1... Also the r1.1 release of the editor misses some important fixed (especially in that area you are interested in: serialization) which are applied since r1.2... only r2.0 will have Silverlight 2 beta 2 support...

> For instant, I want to save a paragraph which includes mixing text and some textbox with text content in

This is of course possible and shown in the demo shipped with the RTE release... just click on "Insert Button" for example..

> (for example, saving to Xml) & load this paragraph into xaml page

Currently the editor does only support binary serialization, a custom format. Saving the content as XAML depends on the existence of XamlWriter, which was not included in silverlight 2 beta 1 and I don't know if it is in Beta 2.
Also it might cause some trouble and if you once saved the content to something other than the internal binary format you won't be able to edit it again or display it in the editor!

>but I'm not sure the SnapShot class can help...

No the snapshot will only support binary serialization....

>Could you please give me some directions to archive this?

The only thing you can do right now is to look at the implementation of the binary serialization. If you are a little bit familiar with Silverlight and XAML you should have no major problems to write a custom XAML serializer and you would be welcome to publish it here if it works ;-)... Just look at "Snapshot.Serialize()"; I think all you have to do is to loop through the LineItems-Enumeration as shown in the binary serialization and instead of using it, just provide your own implementation using an XamlWriter to serialize each single LineItem...

I hope this helps... If you have further problems don't hestitate to ask ;-)

regards
chris
Coordinator
Jun 10, 2008 at 6:14 PM
Edited Jun 10, 2008 at 6:22 PM
Just a hint, because many people are asking the same question...

Why do you want to use a format different to the internal binary one? You may use the readonly mode of the editor to display the text... If you store the text in a custom format you will loose editing capabilities and also it might be that you will run into security issues, because the format that the editor is using internally is verifiable. If you create your own format you have to verify all content yourself and this can be a burden...
In most cases it is just enough to use the readonly mode.

The only case where this approach isnt useful is if you want to export the content to a non-silverlight driven website. Even full-text search with SQL Server is still possible by simply extracting the plain text with "RichTextEdit.Snapshot" and storing it in a database. Instead the first case will at least require a serialization routine which you could build on top of XamlWriter (if yet available). But then you will also need silverlight to display it... Export to HTML would be worth a thought but also this brings serveral disadvantages, because you won't be able to serialize things like buttons and other interactive content supported by my component without much effort!

I just got another aspect... Of course the internal binary format won't be indexed by google... I don't know much abort Google's indexing mechanisms but maybe you could simply bypass this issue by adding the plain text in a hidden HTML-DIV container in the same HTML file that sets up the silverlight environment. This should be easily possible with ASP.NET for example... Even if I think that this could be a little bit tricky because Google may exclude hidden controls from being indexed.