This code example demonstrates how to open and save RichEdit documents from a database binary column.
- Pass a model with a binary property (rich text content to be displayed) to the RichEdit's PartialView.
- Call the RichEditExtension.Open method to open a new document with the specified document ID and content type, and retrieve the binary content from the passed model:
@Html.DevExpress().RichEdit(settings => {
settings.Name = "RichEditName";
settings.CallbackRouteValues = new { Controller = "Home", Action = "RichEditPartial" };
//...
}).Open(Model.DocumentId, Model.DocumentFormat, () => { return Model.Document; }).GetHtml()
- Click the Save ribbon command to initiate a save operation for the active document.
- Use the RichEditSettings.Saving property to save a document in a byte array.
- Call the RichEditExtension.SaveCopy method to get the active document as a byte array, save it to the related bound model's binary property, and set the Handled property to
true
to prevent the default document processing:
settings.Saving = (s, e) => {
byte[] docBytes = RichEditExtension.SaveCopy("RichEditName", DevExpress.XtraRichEdit.DocumentFormat.Rtf);
DXWebApplication1.Models.DataHelper.SaveDocument(docBytes);
e.Handled = true;
};
(you will be redirected to DevExpress.com to submit your response)