Using csIniFile to store information in an INI file.

This demonstration shows an example of using an INI file in a web application. The files needed are included in the zip file with the sample component. If you have not downloaded it you can get it here.

There are 4 ASP files, which must all be put in the same folder. It must be web shared, set to execute scripts and the csIniFile component must be registered. It assumes the trial version, csIniFileTrial, is being used. The INI file will be created when the application runs. The file "control.asp" is the intended starting page.

The INI file stores sizes and font styles for some different html features. These can be modified on a control panel page, and shown in action on a sample page. There is another page which shows the contents of the INI file.

File Description
control.asp Allows the selection of different style attributes using a form. The current values are shown, with defaults used if the INI file is not present.
style.asp This file reads the data and creates a string which will be used inside a pair of <style> </style> tags. It is called as an include file.
samplepage.asp This uses the output string from the include file "style.asp". It displays some headings and text using the style parameters set in the INI file.
showini.asp This loops through the INI file showing each section, key and value.

It should be easy to follow by viewing the code, but some points are worth an explanation.

Control.asp

This script has two subroutines listed before the main body. The IniFile object is created in the main body before calling either subroutine. In summary, the script is as follows:

<%
Sub Section1
'Display the form
'Read the current values from the INI file and add them to the option
'boxes as selected values.

.
.
End Sub

Sub Section2
'Read the form variables into the INI file.
'The current date/time is also stored (Now)

.
.
'Call Section1 to display the form.
End Sub

'The main body of the script checks the form variable "Section" to
'determine whether to call Section1 or Section2.
'The object is created for use in both subroutines.

%>

Style.asp

This is called as an include file. It sets the value of two string variables, "Style" and "Modified" for use by another script. It is really just string manipulation. Note that "Chr(13)" is the carriage return character, and this is needed to produce a valid <style> description.

Samplepage.asp

This uses the "Style" variable defined in "Style.asp". The use of an include file means that a minimum amount of ASP code is required in the file. The sample text is then formatted as defined by the settings in the INI file.

The line:

<!--#include file="style.asp"-->

Is the equivalent of having the entire text from "style.asp" at this point in the page.

The style block is filled using the "Style" string variable. This can be seen by viewing the html source when the page is running in the browser.

Showini.asp

This displays the contents of the INI file by looping through the sections and keys and looking up each value. It also checks if the number of sections is zero to determine if there is an INI file by that name.

In practice, maintaining style settings across an entire site would be done with a cascading style sheet. However, this does show a number of the component's functions in use in a visual way.