Download test files and attachments
Public Sub TestFilesAndAttachments(theTest As TDAPIOLELib.Test)

' Download test files and attachments
        
' This routine gets a test object and
'  first downloads the script files and then the attachments.
' The debug outputs are based on test:
' "OTA_DEMO_SUBJECT\OTA_SUBJECT_level1\OTA_SUB_1.2\SimpleVAPI-XP"

    Dim TestAttachFact As AttachmentFactory
    Dim attachList As List, TAttach As Attachment
    Dim TestAttachStorage As IExtendedStorage
    Dim TestStorage As IExtendedStorage
    Dim TestDownLoadPath As String, AttachDownLoadPath$
    Dim isFatalErr As Boolean
    Dim OwnerType As String, OwnerKey As Variant

'---------------------------------------
' Get the test storage.
    Dim NullList As List
    Set TestStorage = theTest.ExtendedStorage
    TestStorage.ClientPath = _
        "c:\" & theTest.name & "\testStorage"
'-------------------------------------------------------
' Use IExtendedStorage.LoadEx to get the test files.
    TestDownLoadPath = _
        TestStorage.LoadEx("", True, NullList, isFatalErr)
    Debug.Print "Fatal error = " & CStr(isFatalErr)
    'Fatal error = False
    Debug.Print "The test download path: " & TestDownLoadPath
'   The test download path: c:\SimpleVAPI-XP\testStorage
' For this test, the files downloaded by
'   TestStorage.LoadEx are:
'      script.vbs
'      test.sr
'---------------------------------------
' Get the Attachments.
    Set TestAttachFact = theTest.Attachments
    TestAttachFact.FactoryProperties OwnerType, OwnerKey
    Debug.Print "OwnerType = " & OwnerType & ", " _
        & "OwnerKey = " & OwnerKey; ""
'   OwnerType = TEST, DOMAIN:OTA~PROJECT:123.123.123.123@@OTA@@VC~TYPE:TEST~ID:17
'
'----------------------------
' Get the list of attachments and go through
'   the list, downloading one at a time.
    Set attachList = TestAttachFact.NewList("")
    For Each TAttach In attachList
      With TAttach
        Debug.Print "----------------------------"
        Debug.Print "Download attachment" & vbCrLf
        Debug.Print "Before setting path"
        Debug.Print "The attachment name: " & .name
        Debug.Print "The attachment server name: " & .ServerFileName
        Debug.Print "The filename: " & .FileName
'
'       Before setting path
'       The attachment Name: TEST_98_SampleAttachment.txt
'       The attachment server name: C:\Program Files\Mercury Interactive\Quality Center\repository\qc\Default\Steve_85_Doc\Attach\TEST_98_SampleAttachment.txt
'       The filename: C:\DOCUME~1\steves\LOCALS~1\Temp\TD_80\423af35f\Attach\TEST98\TEST_98_SampleAttachment.txt

'----------------------------------------------------
' Use Attachment.AttachmentStorage to get the
'  extended storage object.
        Set TestAttachStorage = .AttachmentStorage
        TestAttachStorage.ClientPath = _
            "c:\" & theTest.name & "\attachStorage"
'----------------------------------------------------
' Use Attachment.Load to download the attachment files.
        TAttach.Load True, AttachDownLoadPath
' Note that the Attachment.FileName property changes as a result
' of setting the IExtendedStorage.ClientPath.
        Debug.Print vbCrLf & "After download"
        Debug.Print "Down load path: " & AttachDownLoadPath
        Debug.Print "The filename: " & .FileName
'       After download
'       Down load path: c:\SimpleVAPI-XP\attachStorage
'       The filename: c:\SimpleVAPI-XP\attachStorage\TEST_98_SampleAttachment.txt

      End With
    Next TAttach

End Sub