Platform SDK: Team Productivity Update

Saving Configuration Information

The information collected from the user during the configuration process is temporarily saved to a text file. This process occurs when the Configure URL calls the ConfigureSaveToFile URL (urlConfigureSaveToFile.asp file). The values contained in the text file are later read by the Deploy URL and saved to a new instance database.

To save this configuration information permanently to a file for a Team Workspace instance of the Expense Report application, the script follows several steps. First, the script indicates the file location where the installed version of the Expense Report application resides on the server. Using the MapPath method of the ASP Server object, the script finds the physical path that corresponds to the application's virtual root. The script also sets a variable to hold the name of a text file. This text file stores an instance number for the application copy. This text file resides in the same directory as the application source.

' Setup names / paths
SourceName = "expense"    ' Name of the application
NextInstanceNumberFilename = "NextInstanceNumber.txt"  ' Name of the file were we will keep the instance counter
SourcePath = Server.MapPath("/" & SourceName)    ' Current physical directory
ExpenseReportConfigFilename = "Expense#_Config.txt"

Using the intrinsic ASP Server object, the script creates an instance of the VBScript Scripting Run-time FileSystemObject to gain access to the server computer's file system. The BuildPath method designates a path for the text file location and then appends a name to the file. In this case, the script uses the current directory (the value passed in Server.MapPath) and "NextInstanceNumber.txt", the string stored in the NextInstanceNumberFilename variable.

' Get next instance number
Set oFileSystem = Server.CreateObject("Scripting.FileSystemObject") 
NextInstanceNumberPathFilename = oFileSystem.BuildPath(SourcePath, NextInstanceNumberFilename)  
Set oFileSystem = Server.CreateObject("Scripting.FileSystemObject") 
Set oFile = oFileSystem.OpenTextFile(NextInstanceNumberPathFilename, 1, True) 
If oFile.AtEndOfStream = True Then    
    NextInstanceNumber = 1    
Else
    NextInstanceNumber = oFile.ReadAll
End If
oFile.Close

There are two configuration values that are requested during the Expense Report configuration process. The variables that hold these values are AccountsPayableNTUsername and MileageRate. These values are saved as global values.

' Get the config values from the calling form
AccountsPayableNTUsername = trim(Request.Form("AccountsPayableNTUsername").Item)
MileageRate = trim(Request.Form("MileageRate").Item)

Next, the save configuration process saves the configuration values to a text file and then closes the file.

' Save configuration values to text file
ExpenseReportConfigPathFilename = SourcePath & "\" & Replace(ExpenseReportConfigFilename,"#", NextInstanceNumber)
Set oFile = oFileSystem.OpenTextFile(ExpenseReportConfigPathFilename, 2, True) 
oFile.Write AccountsPayableNTUsername & "|" & MileageRate
oFile.Close

The save configuration process then closes the Expense Report Configuration window and returns the XML values.

' Close the window and return XML
%>
<HTML>
<HEAD>
</HEAD>
<BODY onLoad="window_onLoad()">
<SCRIPT language="JScript">
function window_onLoad()
{
    window.external.exit("<?xml version='1.0'?><Result><Code>0</Code><Description>Configure URL returned successfully.</Description></Result>");
}
</SCRIPT>
</BODY>
</HTML>