The LoadText method accepts a physical file, a FileStream, a string or a byte array to load documents into the web editor.

This sample shows how to load a document in the controller and pass it as a ViewModel to the view in order to load a document.

In the controller method Index, the document is loaded into a MemoryStream and then stored in the ViewModel Document that holds the document as a Base64 encoded string. This ViewModel is returned to the actual view.

public ActionResult Index()
{
Document document = new Models.Document();
MemoryStream ms = new MemoryStream();
FileStream fs;
// load the document into a stream
using (fs = System.IO.File.OpenRead(
Server.MapPath("/App_Data/documents/document.docx")))
{
fs.CopyTo(ms);
document.BinaryDocument = Convert.ToBase64String(ms.ToArray());
}
// forward the document to the view
return View(document);
}
view raw Controller.cs hosted with ❤ by GitHub

In the view, the Base64 encoded string is converted back into a byte array and loaded using the LoadText method into the web editor.

@model tx_loadStream.Models.Document
@using TXTextControl.Web
@using TXTextControl.Web.MVC
@Html.TXTextControl().TextControl(settings => {
settings.Dock = TXTextControl.Web.DockStyle.Window;
}
).LoadText(Convert.FromBase64String(Model.BinaryDocument),
BinaryStreamType.WordprocessingML).Render()
view raw Index.cs hosted with ❤ by GitHub

Download the sample from GitHub and test it on your own.