Products Technologies Demo Docs Blog Support Company

HTML5 Web Editor: Loading and Saving Documents

Documents can be easily loaded using ASP.NET code-behind code with the Web.TextControl.LoadText and Web.TextControl.SaveText methods that accept file names, FileStreams and memory variables such as byte and string arrays. To load a document from a physical file, the following code is required: TextControl1.LoadText(Server.MapPath("/documents/sample.docx"), TXTextControl.Web.StreamType.WordprocessingML); In order to save a document, the SaveText method is used:…

HTML5 Web Editor: Loading and Saving Documents

Documents can be easily loaded using ASP.NET code-behind code with the Web.TextControl.LoadText and Web.TextControl.SaveText methods that accept file names, FileStreams and memory variables such as byte and string arrays.

To load a document from a physical file, the following code is required:

TextControl1.LoadText(Server.MapPath("/documents/sample.docx"),
    TXTextControl.Web.StreamType.WordprocessingML);

In order to save a document, the SaveText method is used:

TextControl1.SaveText(Server.MapPath("/output/" + sFilename),
    TXTextControl.Web.StreamType.WordprocessingML);

Web.TextControl must be initialized completely in order to accept LoadText calls. Therefore, it exposes another method to load documents: Web.TextControl.LoadTextAsync. This method loads the text asynchronously when the HTML5 Web Editor is initialized and loaded completely.

In order to load a document in the Page_Load event of an ASPX Web Form, the following code is used:

TextControl1.LoadTextAsync(Server.MapPath("/documents/template.docx"),
    TXTextControl.Web.StreamType.WordprocessingML);

Web.TextControl is updated and synchronized with the server automatically using the Web Sockets protocol. In case, you want to use other server-side (runat="server") elements such as buttons on the same form, make sure that they are embedded in an AJAX UpdatePanel and doesn't post back the complete page. A typical body would look like this:

<body>
 <form id="form1" runat="server">
  <div>
   <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
   <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
     <asp:Button ID="Button1" runat="server" Text="Load Document" />
    </ContentTemplate>
   </asp:UpdatePanel>
   <cc1:TextControl ID="TextControl1" runat="server" />
  </div>
 </form>
</body>

More information and tutorials can be found in the documentation.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

ASP.NETDocumentViewerHTML5

Creating an ASP.NET MVC DocumentViewer Application With Razor

Create a simple ASP.NET (MVC) application that uses the HTML5 document viewer.


ASP.NETHTML5Razor

Creating an ASP.NET MVC Application With Razor

This tutorial shows how to integrate TextControl.Web into an MVC application with Razor.


ASP.NETReportingHTML5

Creating Your First ASP.NET Reporting Application

This tutorial shows how to use the MailMerge component in an ASP.NET Web application to merge a template with data to create an Adobe PDF document.


ASP.NETAjaxHTML5

Creating an ASP.NET Web Forms AJAX Application

This tutorial shows how to use the HTML5 based TextControl to create a Web based word processor and template designer. Using the built-in File menu, you can load and save documents from and to a…


AzureHTML5MVC

Using an Azure Load Balancer with Web.TextControl

LOB (line of business) applications are often deployed with a Load Balancer that distributes incoming traffic to healthy virtual machines or cloud services. When deploying an application, that…