Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

RichEdit - How to save and load documents from a database

$
0
0
This code example demonstrates how to save and restore RichEdit documents from a database using a binary column.

Load document:
- Pass a model with a binary property (rich text content to be displayed) to the RichEdit's PartialView.
- Use the RichEditExtension.Open method to open a new document with the specified/unique document ID and the necessary rich content type, and retrieve the binary content from the passed model (see the RichEditPartial source code file):

[C#]
@Html.DevExpress().RichEdit(settings=>{settings.Name="RichEditNameHere";settings.CallbackRouteValues=new{Controller=...,Action="ActionMethodThatHandlesRichEditCallbacks"};}).Open(UNIQUE_DOCUMENT_ID_HERE,RICH_TEXT_FORMAT_HERE,()=>{returnMODEL_BINARY_PROPERTY_HERE;}).GetHtml()

[VB.NET]
@Html.DevExpress().RichEdit( _Sub(settings) settings.Name = "RichEditNameHere" settings.CallbackRouteValues = NewWith {.Controller = "...", .Action = "ActionMethodThatHandlesRichEditCallbacks"}EndSub).Open(UNIQUE_DOCUMENT_ID_HERE, RICH_TEXT_FORMAT_HERE, _Function()Return MMODEL_BINARY_PROPERTY_HEREEndFunction).GetHtml()

Save a document:
- Click the built-in toolbar's Save button/item.
- Handle the action method specified via the RichEditSettings.CallbackRouteValues.Action property.
- Invoke the RichEditExtension.GetCallbackResult method (to return a callback result for all callback operations) and subscribe to the DocumentSavingEventHandler Saving event.
- Retrieve the modified content via the RichEditExtension.SaveCopy method, save it to the related bound model's binary property, and set the EventArgs Handled property to True (see the HomeController source code file):

[C#]
publicActionResultActionMethodThatHandlesRichEditCallbacks(){returnRichEditExtension.GetCallbackResult("RichEditNameHere",p=>{p.Saving(e=>{byte[]docBytes=RichEditExtension.SaveCopy("RichEditNameHere",DocumentFormat.RichTextFormatHere);//save "docBytes" to dbe.Handled=true;});});}

[VB.NET]
PublicFunction ActionMethodThatHandlesRichEditCallbacks() As ActionResultReturn RichEditExtension.GetCallbackResult("RichEditNameHere", Sub(p) p.Saving(Sub(e)Dim docBytes() AsByte = RichEditExtension.SaveCopy("RichEditNameHere", DocumentFormat.RichTextFormatHere)'save "docBytes" to db e.Handled = TrueEndSub)EndSub)EndFunction

See Also:
WebForms Version:
T352034: ASPxRichEdit - How to save and load documents from a database

Viewing all articles
Browse latest Browse all 7205

Trending Articles