Utility components ASPIniFile component

Manual Installtion (use installer if possible)
Register component using regsvr32 ASPIniFile.dll.

General
ASPIniFile component implements simple operations over Windows INI files - such as get/set string/integer values using sections. It is implemented as Free threaded and is compiled as ANSI. Thus it can be used on both NT and consumer windows platforms.

Usage
Component name is ASPIniFile i.e.create component's object as follows:
Server.CreateObject("ASPIniFile.IniFile")
Class ID: {BAA1BD2B-3077-11D3-959F-0040332BA2EA}

Object

IniFile
Properties:
Name access Description
strFileName read/write BSTR - INI file name. Warning it can be any file - be careful !
strCurrentSection read/write BSTR - Name of the current section for reading/writing values
Integers(BSTR) read/write Indexed property - returns or sets integer value in the currently selected section (through strCurrentSection property).

Parameter - value name

Strings(BSTR) read/write Indexed property - returns or sets string value in the currently selected section (through strCurrentSection property).

Parameter - value name

 

Methods:
Methods of this object are another versions of the Integers and Strings properties 

Name Returns Description
GetString(
    BSTR bstrValueName
)
BSTR Returns value with given name in current section
SetString(
   BSTR bstrValueName,
   BSTR bstrValue
)
Sets value with given name in current section
GetInt(
    BSTR bstrValueName
)
long
(Number)
Returns value with given name from current section as number
SetInt(
   BSTR bstrValueName,
   long lValue
)
Sets value with given name in current section

Remarks
Can be used also in any scripting host such as Windows Scripting Host, Internet Explorer, ALP etc.

Sample:

<%@ Language=VBScript %>
<%
    Dim ini
    Set ini = Server.CreateObject("ASPIniFile.IniFile")
    ini.strFileName = Request.ServerVariables("APPL_PHYSICAL_PATH") & "data\CommonSite.ini"
    ini.strCurrentSection = "ODBC"
    If ini.Strings("DataSource") = "" Then
        ini.Strings("DataSource") = Request.ServerVariables("APPL_PHYSICAL_PATH") & "data\SiteData.mdb"
    End If
    If ini.Strings("Provider") = "" Then
        ini.Strings("Provider") = "Microsoft.Jet.OLEDB.3.51"
    End If
   
' If this page was called through form submission
    If Request.Form("DataSource").Count > 0 Then
        ini.Strings("DataSource") = Request.Form("DataSource")
        ini.Strings("UserID") = Request.Form("UserID")
        ini.Strings("Password") = Request.Form("Password")
        ini.Strings("Provider") = Request.Form("Provider")
    End If
%>
<!-- HTML code and little JScript that fills a form -->

<%@ Language=JScript %>
<%
    var ini = Server.CreateObject("ASPIniFile.IniFile");
    ini.strFileName = Request.ServerVariables("APPL_PHYSICAL_PATH") + "data\\CommonSite.ini";
    ini.strCurrentSection = "ODBC";
    if (ini.Strings("DataSource") == "") {
        ini.Strings("DataSource") = Request.ServerVariables("APPL_PHYSICAL_PATH") + "data\\SiteData.mdb";
    }
    if (ini.Strings("Provider") == "") {
        ini.Strings("Provider") = "Microsoft.Jet.OLEDB.3.51"; 
    }
   
// If this page was called through form submission
    if (Request.Form("DataSource").Count > 0) {
        ini.Strings("DataSource") = Request.Form("DataSource");
        ini.Strings("UserID") = Request.Form("UserID");
        ini.Strings("Password") = Request.Form("Password");
        ini.Strings("Provider") = Request.Form("Provider");
    }
%>
<!-- HTML code and little JScript that fills a form -->

This sample assumes that site configuration file is in the data subdirectory of the ASP application directory. On load it checks values for DATA source configuration in the INI file. If file does not exist or values are empty it fills some default values. If page call was result of form submission it transfers values from form to the INI file.

 

newObjects Copyright 2001-2005 newObjects [ ]