Getting Remote Files With ASP Continued - PerformUpdate() Explained
(Page 3 of 5 )
Once we are sure we want to perform the update (the license key has checked out as legitimate), we can begin creating the XML document to send back to the client. In this example, the parent node of our XML is ‘MALL23’. You can customize this for your own application.
Within the parent node, there are three child nodes: MESSAGE, VERSION, and CODE.
- The MESSAGE node holds error or success codes, or action codes for the client to perform.
- The VERSION node holds the version that the client is being updated to. This way, the client will know what version it will be on once the update has been completed. As I mentioned in the previous article, it would be wise to store this in a local config file on the client, and read the version each time.
- The CODE node is optional code to run on the client that is not part of the normal update. This can be used for many purposes, to activate or deactivate a client, grant or revoke administrator rights, rename or move files, reverse product SKUs (kidding!)...
Sub PerformUpdate()
Dim oRoot, oElement, objFolder, objItem2
xmlDOMDocument.loadXML "<MALL23 />"
Set oRoot = xmlDOMDocument.documentElement
Set oElement = xmlDOMDocument.createElement("MESSAGE")
oElement.nodeTypedValue = "error, success or action messages to send to the client"
oRoot.appendChild oElement
Set oElement = xmlDOMDocument.createElement("VERSION")
oElement.nodeTypedValue = "version that the client is being update to"
oRoot.appendChild oElement
Set oElement = xmlDOMDocument.createElement("CODE")
oElement.nodeTypedValue = "misc. code to be processed by the client application"
oRoot.appendChild oElement
Set objFolder = fsoFileObject.GetFolder(Server.MapPath("Updates/"))
For Each objItem2 In objFolder.Files
Call ProcessFile(objItem2.Path)
Next
Set objFolder = Nothing
xmlDOMDocument.save(Response)
End Sub
For this example, the update files exist in a subfolder called “Updates”. You can change it to whatever you like. The most practical thing to do in a professional application with many subfolders is to put the exact subfolders within the Updates folder, and traverse through them. You can automate your code versioning system to place a copy of the updated files into their respective subfolders in the ‘update’ directory.
The PATH node (see the Client Side Parse section of the previous article) contains the relative folder path for each file anyway. That way, the exact folder structure will be transmitted and retained on the client version of the application. For the sake of simplicity, the example just loops through all the files in the ‘Updates’ folder, no subfolders.
You’ll notice that for each file in the ‘Updates’ folder, the ProcessFile() subroutine is called. Let’s examine that now.
Next: ProcessFile() Explained >>
More ASP Code Articles
More By Justin Cook