How to save KTML 4 content to a file

In this tutorial you will learn how to create a page that contains the KTML control and which saves edited content to a file on the disk.

In order to follow this tutorial you need:

  1. The KTML standalone package for your particular server model, Dreamweaver extension or Visual Studio control.

  2. Coding knowledge for the scripting language you intend to use. Code is provided, but in order to customize it to your exact needs, you should know how to change it.

In this tutorial you will create two files:

  1. index - in the site root, displays content from the file

  2. edit - also in the site root, contains the KTML control applied on a form, and logic to save content into the file.

To create the site structure, follow the next steps:

  1. Using a file explorer of choice, browse to the folder that is also the document root for your server.

  2. Create a new folder, named as the site you intend to create - e.g. KTMLWrite.

  3. Open the folder and create two empty files - index and edit.
    Note:
    Do not forget to add the correct extension for these files, according to the language script to use.
    Note:
    If using ASP .NET 1.1 or 2.0 you will have to name the first file default.

  4. Also create an empty html file where content will be saved - name it out.htm.

 

Create the display page

First you will build the page that displays content already saved within the out.htm file.

To create this page, follow the instructions below:

  1. Open the index/default file with a text editor. This page will have to contain two sections: code above the <html> tag that will open and read the file, check if a form has been submitted and if true, saves the content to the file. The second section contains HTML code for the page, with a link to edit the content and server-side code that displays the dynamic content in the file.

  2. On top of the file add the following code (pick the snippet that is appropriate for your scripting language):

  3. Next you have to add code that displays the content and a link to the edit page. This is added after the code above:

  4. With this you are done creating the page that displays file content. Save it and you can test it by loading it in a browser. Because the out.htm file does not contain anything yet, the page will simply display the edit link.

 

Next you must create the page that contains the KTML control.

 

Create the edit page

In this section only instructions on how to build the basic page are provided. For instructions on how to actually apply the KTML control, see the topic under Manually Install KTML 4 in Your Site that is appropriate to your particular scripting language.

To create the page that contains the form and saves the content to a file, follow the instructions below:

  1. Open the edit file in a text editor.

  2. On top of the page add code that will open the file and load the content into the editor:

  3. Next you have to add the form that will allow editing content. Since the only thing to change is the file content, the form will only have a textarea and a submit button. The HTML code is:

  4. The last thing to do is to enhance the page by applying the  KTML control as shown here. When editing content thereafter, it will be saved to the file instead of a database field.