first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

ASP, VBScript and ADO: "Updating" an ADO-Generated XML File

<%@ EnableSessionState=False LANGUAGE=VBScript %> <%Option Explicit%> <!--#include virtual="./INC/ADOVBS.asp"--> <!--#include virtual="./INC/Classes/HTMLPage.asp"--> <% Dim objFileSys,vPath Dim objRS,vFieldArray,vArray

'Get root folder.    
Set objFileSys = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

'Create and disconnect Recordset object.
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set objRS.ActiveConnection = Nothing
objRS.CursorType = adOpenKeyset
objRS.LockType = adLockOptimistic
objRS.CursorLocation = adUseClient
    
vPath = Server.MapPath(&quot;./&quot;) & &quot;&bsol;&bsol;dirADO.xml&quot;
If objFileSys.FileExists(vPath) Then
    'Strange but true: open the persisted XML file
    'and then delete it to save a new one.
    Call objRS.Open(vPath,,,,adCmdFile)
    objFileSys.DeleteFile(vPath)
    'This technique is suggested in MS KB article Q245367.
    'Note: because of this, the IIS Anonymous user must have
    'Change permissions to the root documents folder.
    'This creates a security hole and therefore sucks.

    vFieldArray = Array(&quot;rootFolder&quot;,&quot;subFolder&quot;,&quot;fileName&quot;,&quot;fileDescription&quot;)
    vArray = Array(&quot;docs&quot;,&quot;issues&quot;,&quot;file.pdf&quot;,&quot;PDF file&quot;)
    Call objRS.AddNew(vFieldArray,vArray)

    Call objRS.Update
Else
    Call basCreateRS(objRS)
    Call objRS.Open
End If

Call objRS.Save(vPath,adPersistXML)

'Clean up.
Call objRS.Close
Set objRS = Nothing
Set objFileSys = Nothing

Sub basCreateRS(objRS)
    'Define Field objects.
    Call objRS.Fields.Append(&quot;rootFolder&quot;,adBSTR,256,adFldMayBeNull)
    Call objRS.Fields.Append(&quot;subFolder&quot;,adBSTR,256,adFldMayBeNull)
    Call objRS.Fields.Append(&quot;fileName&quot;,adBSTR,256,adFldMayBeNull)
    Call objRS.Fields.Append(&quot;fileDescription&quot;,adBSTR,1024,adFldMayBeNull)
End Sub

%>

mod date: 2002-05-28T18:02:52.000Z