Back to Devexpress

RichEditBuilder.Open(Func<Byte[]>, DocumentFormat, String) Method

aspnetcore-devexpress-dot-aspnetcore-dot-richedit-dot-richeditbuilder-dot-open-x28-system-dot-func-system-dot-byte-devexpress-dot-aspnetcore-dot-richedit-dot-documentformat-system-dot-string-x29.md

latest3.0 KB
Original Source

RichEditBuilder.Open(Func<Byte[]>, DocumentFormat, String) Method

Opens a document specified by an array of bytes.

Namespace : DevExpress.AspNetCore.RichEdit

Assembly : DevExpress.AspNetCore.RichEdit.v25.2.dll

NuGet Package : DevExpress.AspNetCore.RichEdit

Declaration

csharp
public RichEditBuilder Open(
    Func<byte[]> contentAccessorByBytes,
    DocumentFormat format,
    string documentName = null
)

Parameters

NameTypeDescription
contentAccessorByBytesFunc<Byte[]>

A method delegate that gets a byte array from which to open the document.

| | format | DocumentFormat |

An object that specifies the document format.

|

Optional Parameters

NameTypeDefaultDescription
documentNameStringnull

The name of the file to open. Also serves as an exported file name.

|

Returns

TypeDescription
RichEditBuilder

A RichEditBuilder that allows you to configure the Rich Text Editor.

|

Remarks

cshtml
<script>
    function SaveRichDocument(data) {
        richEdit.save();
    }
</script>
<button type="button" class="btn btn-primary" onclick="SaveRichDocument()">Save</button>

@(Html.DevExpress().RichEdit("richEdit")
    .Width("100%")
    .Height(800)
    .Ribbon(ribbon => ribbon
        .ActiveTabIndex(0)
    )
    .ExportUrl(Url.Action("SaveAction"))
    .Open(() => { return Model.ContentAccessorByBytes; }, DevExpress.AspNetCore.RichEdit.DocumentFormat.OpenXml)
)
csharp
public IActionResult Index() {
    var fileBytes = System.IO.File.ReadAllBytes(Path.Combine(Env.ContentRootPath, "Example.docx"));
    var viewmodel = new RichEditViewModel(fileBytes);
    return View(viewmodel);
}
public IActionResult SaveAction(string base64, string fileName, DevExpress.AspNetCore.RichEdit.DocumentFormat format) {
    byte[] fileContents = System.Convert.FromBase64String(base64);
    System.IO.File.WriteAllBytes(Path.Combine(Env.ContentRootPath, "Example.docx"), fileContents);
    return Ok();
}

View Example: How to load/save documents from/to a database

See Also

RichEditBuilder Class

RichEditBuilder Members

DevExpress.AspNetCore.RichEdit Namespace