TX Text Control Source Code Library

Working with files in Internet Explorer

One of the advantages of TX Text Control is that it runs in Microsoft Internet Explorer. This allows you to let end-users edit their documents in MSIE without having to install an application on their PC.

In previous code snippets (see the related code snippets below), we have illustrated how this can be achieved. This example, builds on what we have previously learned and shows how it is possible to let end-users load, edit and save documents on a WWW server using a standard browser-based interface. This offers the following benefits:

  • Central storage of all documents
  • Easier backups for the network administrator
  • Create decentralized, web-based word processing apps
  • Access documents from any Internet-enabled PC
  • Enable multiple people to work on one document.

For the purpose of loading and saving, we will be using HTTP - no other protocols, such as FTP are involved.

Code Overview

The main document (index.asp) holds TX Text Control. It should look familiar to those who have studied the previous Microsoft Internet Explorer samples.

Using the JavaScript function OpenDocManager() we open a small window, which will handle the loading and saving of the documents. This is necessary because after each load/save action the document needs to be refreshed. If we used the main document with TX Text Control to do that, we would lose all the text in the control each time as the control is reinitialized.

The new window (docman.asp) shows the files that are currently stored on the server, information about these files and links to load and delete them.

Furthermore, there is an input box and a button that allows the current document to be saved. Note that thus far, there is no error checking, hence documents will be overwritten without query. :-)

Also, the file format in which the document is saved is simply determined by its file extension. Currently, you can only save to RTF (.rtf) or HTML (.html) format. This is because you can save only text-based formats using the following approach.

Loading Documents

This is the easier part. We use the Microsoft INet Control to load the document from the web server. The VBScript function OpenServerFile() does this for us.

Details on how it works, can also be found in this previous sample.

Saving Documents

Saving documents on the server is a little trickier. We are going to use the common HTTP POST to realize this.

In doing so we implement a custom submit handler that is called once the user presses the submit button. Here is the HTML code of the form:

<form name="MyForm" action="save.asp" method="post" onsubmit="MySubmit()"> <input type="hidden" id="data" name="data" value=""> <input type="text" name="file" size=50> <input type="submit" name="submit" value="Save"> </form>

Also note, that there is a hidden field called 'data'. So, all we have to do is get the contents of TX Text Control and write them to the hidden field when the submit handler is called. Here is the code to do that:

Sub MySubmit() Dim doc_data if(UCase(Right(document.all("file").value, 4)) = "HTML") Then doc_data = Opener.objTX.SaveToMemoryBuffer(doc_data, 4, 0) elseif(UCase(Right(document.all("file").value, 3)) = "RTF") Then doc_data = Opener.objTX.SaveToMemoryBuffer(doc_data, 5, 0) End If MyForm.data.value = doc_data End Sub

Simply call SaveToMemoryBuffer and that is it - quite simple. Server-side you only have to write the data to a file (or database) and you are done.

As the sample is written in ASP, a Microsoft IIS server is recommended to execute the code; however as it follows the HTTP specification, it could also be ported to PHP without too much effort. The POSTed data would be available in the PHP super global variable $_POST.

There are lots of other things you can create by expanding this sample. For example, you could write a content management system for websites. Indeed, we will be taking a much closer look at the topic very shortly.

As ever, if you would like to talk to us about this or any other TX Text Control support issue, you can find complete contact information on the contact page.

 
 

Products

Support

Downloads

Corporate

Buy Now