QC中添加附件,删除附件和下载附件
'Function to Add an attachment to a specified object
Public Function AddAttachment(ByVal TOObject, ByVal FileName)
Dim oNewAttachment
'Upload the new file
Set oNewAttachment = TOObject.Attachments.AddItem(Null)
oNewAttachment.FileName = FileName
oNewAttachment.Type = 1 'TDATT_FILE
oNewAttachment.Post
'Return the new attachment
Set AddAttachment = oNewAttachment
End Function
'To add the attachment to CurrentRun of the test we can just call it below way
Call AddAttachment(QCUtil.CurrentRun, "C:\File.txt")
'Function remove an existing attachment from an object
Public Function RemoveAttachment(ByVal FromObject, ByVal FileName)
Dim oAttachments, oAttachment
Set oAttachments = FromObject.Attachments.NewList("")
'No attachments removed
RemoveAttachment = False
For each oAttachment in oAttachments
If oAttachment.Name(1) = FileName Then
FromObject.Attachments.RemoveItem(oAttachment)
'Attachment has been removed
RemoveAttachment = True
Exit Function
End If
Next
End Function
'To remove the attachment to CurrentRun of the test we can just call it below way
Call RemoveAttachment(QCUtil.CurrentRun, "C:\File.txt")
'Function to download attachment from a QCObject to a specified folder
Public Function DownloadAttachment(ByVal FromObject, ByVal TOPath, ByVal filename)
Dim oAttachments, oAttachment
Set oAttachments = FromObject.Attachments.NewList("")
'No attachments removed
DownloadAttachment = False
Dim FSO
Set FSO = CreateObject("Scripting.Dictionary")
For Each oAttachment In oAttachments
If oAttachment.Name(1) = FileName Then
'Load the attachment to local drive
oAttachment.Load True, ""
'Attachment was downloaded
DownloadAttachment = True
'Copy the file from temporary downloaded location to the TOPlace folder
FSO.CopyFile oAttachment.FileName, TOPath & oAttachment.Name(1),True
Exit Function
End If
Next
End Function