Products Technologies Demo Docs Blog Support Company

HTML5: Loading Local Documents - Part 2

Building on Part 1, this tutorial hides the HTML input element with CSS and attaches a custom JavaScript event to the ribbon bar Open button. The event intercepts the default action and triggers the local file dialog, enabling uploads from the file system or connected cloud services.

HTML5: Loading Local Documents - Part 2

In a recent blog entry, we showed how to load a local document using pure Javascript and an HTML input element. In this second part, we show how to hide the HTML input element and to overwrite the Open functionality in the ribbon bar.

The input element is hidden using the CSS property display:

<input style="display: none; margin-bottom: 20px;" type="file" id="fileinput" />
<cc1:TextControl ID="TextControl1" runat="server" />

Using Javascript, a new event is attached to the Load menu item of the ribbon bar. The newly attached event is raised before it is bubbled to Web.TextControl. This enables the cancellation of the default functionality of the ribbon item in order to add your own action:

TXTextControl.addEventListener("ribbonTabsLoaded", function (e) {
      addAction();
});

function addAction() {
    document.getElementById("fileMnuItemOpen").addEventListener("click",
        function (e) {
            document.getElementById('fileinput').click();
            e.cancelBubble = true;
        });
}

When clicking the Open menu item now, the local Open File dialog is opened. Users can now upload local files or files from connected cloud services such as OneDrive:

HTML5: Loading local documents - Part 2

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

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Download ZIP

Open on GitHub

Open in Visual Studio

Requirements for this sample

  • Visual Studio 2012 or better
  • TX Text Control .NET Server (trial sufficient)

Reporting

The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.

See Reporting products

Related Posts

ASP.NETReportingHTML5

Creating Your First ASP.NET Reporting Application

The MailMerge and ServerTextControl components of TX Text Control .NET Server for ASP.NET enable server-side reporting in Web Forms. A template.docx merges with XML data via a button click…


ASP.NETReportingAuto Save

Automatically Reconnect to the Server and Recover the Document

When a WebSocket connection drops, the TX Text Control editor automatically reconnects and recovers the document using browser local storage. The implementation saves document state client-side…


ReportingHTML5Widget

JavaScript API: Working with Merge Fields

The TX Text Control JavaScript API enables inserting, deleting, and manipulating merge fields in the HTML5-based document editor. Developers create MergeField objects, add them at specific…


AngularJavaScriptReact

Technology Preview: Embeddable HTML Widget to integrate Document Editing to…

TX Text Control offers a technology preview of an embeddable JavaScript widget that adds document editing to Angular, React, and other web frameworks. Developers add a script tag and create a…


AngularReportingHTML5

Embedding TXTextControl.Web in non-.NET Framework applications like .NET…

The HTML5-based Web.TextControl editor can run inside an IFrame to embed it in non-.NET Framework applications such as .NET Core or AngularJS sites. The hosting page sends structured JSON commands…

Share on this blog post on: