Platform SDK: Team Productivity Update

Removing the Expense Report Application from a Team Workspace

This section discusses how the Expense Report application can be removed from the Team Workspace. When you remove the Expense Report application, the Team Productivity Update calls the Delete URL. This ASP script removes the instance's virtual directory, database, files, and directory.

The script starts by getting the URL source path. The Request object is used to get this path. The Request object retrieves the values that the client browser passed to the server during an HTTP request. The ServerVariables collection is retrieved and then the Split function is used to determine the URL. Also, it is assumed that the script is running in the source directory.

' Get the source path  (Assumes this script is running in the source directory)
URL = Request.ServerVariables("URL")  ' "/expense/urlDropConfigure.asp"
URLParts = Split(URL,"/")    
SourceName = URLParts(1)
SourcePath = Server.MapPath("/" & SourceName)    ' Current physical directory

Next, the instance number of the Expense Report application is determined. To get the instance number, the values contained in the ConfigSessionID element within the Form collection must be retrieved. To do this, the text file containing the instance number must be located and read.

' Get the instance number (using the GUIDSessionID name)
GUIDSessionID = Request.QueryString("GUIDSessionID")
Set oFileSystem = Server.CreateObject("Scripting.FileSystemObject") 
GUIDSessionIDPathFilename = oFileSystem.BuildPath(SourcePath, GUIDSessionID & ".txt")  
Set oFile = oFileSystem.OpenTextFile(GUIDSessionIDPathFilename, 1, False) ' For Read
InstanceNumber = oFile.ReadAll

Once the instance number has been read, the file can be closed.

oFile.Close

At this point, the text file can be deleted.

Call oFileSystem.DeleteFile(GUIDSessionIDPathFilename, True) ' Remove the file
InstanceName = SourceName & InstanceNumber

Next, the instance's virtual directory must be removed. To do this, the virtual directory must be located. Then, the instance's virtual directory can be deleted.

' Remove the instance's IIS Virtual Directory
Set oIIS = GetObject("IIS://" & Request.ServerVariables("SERVER_NAME") & "/W3SVC/1/root")  
oIIS.Delete "IIsWebVirtualDir", InstanceName
Set oIIS = Nothing

Also, the instance's files and physical directory are removed. Once the instance's virtual directory and database have been removed, the files and physical directory are deleted. First, the appropriate path is recognized. Then, the appropriate directory is deleted based on the path information.

' Remove the instance's physical directory / files
WebPath = oFileSystem.BuildPath(SourcePath, InstanceName)     
Call oFileSystem.DeleteFolder(WebPath, True)

Next, the instance's database is removed. First, a connection to the database is established. Then, the database is removed.

' Remove the instance's SQL Server Database
Set oSQLServer = Server.CreateObject("SQLDMO.SQLServer")
Call oSQLServer.Connect("(local)")    ' Use NT integrated security (no UID or PWD)
Set oDatabase = oSQLServer.Databases(InstanceName)
Call oDatabase.Remove()
Set oDatabase = Nothing
oSQLServer.Close
Set oSQLServer = Nothing

Last, the XML stream is returned.

<?xml version='1.0'?>
<TeamAppFactory>
<Result>
    <Code><%= ResultCode%></Code>
    <Description><%= ResultDescription%></Description>
</Result>
</TeamAppFactory>