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

 

转载于:https://www.cnblogs.com/dushuai/articles/2623422.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值