'===============================================================
'Description : Returns the path of downloaded attachment
'===============================================================
'Example Usage :
' If you want to move the downloaded file to c:\ folder
' attpath = DownloadAttachment(“attachmentname”,”Root\D2D\Purchasing”, “TRUE”)
' If you DO NOT want to move the downloaded file to c:\ folder
' attpath = DownloadAttachment(“attachmentname”,”Root\D2D\Purchasing”, “FALSE”)
Public Function DownloadAttachment(TDAttachmentName, TDFolderPath, bMovetoRoot)
Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
Dim otaAttachment 'As TDAPIOLELib.Attachment
Dim otaAttachmentList 'As TDAPIOLELib.List
Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
Dim otaTreeManager 'As TDAPIOLELib.TreeManager
Dim otaSysTreeNode 'As TDAPIOLELib.SysTreeNode
Dim otaExtendedStorage 'As TDAPIOLELib.TreeManager
Dim fso
Dim strPath 'As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set otaTreeManager = QCUtil.TDConnection.TreeManager
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
Set otaAttachmentFactory = otaSysTreeNode.Attachments
Set otaAttachmentFilter = otaAttachmentFactory.Filter
otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & otaSysTreeNode.NodeID & "_" & TDAttachmentName & "'"
Set otaAttachmentList = otaAttachmentFilter.NewList
If otaAttachmentList.Count > 0 Then
set otaAttachment = otaAttachmentList.Item(1)
otaAttachment.Load True, ""
strPath = otaAttachment.FileName
If (bMovetoRoot) Then
If (fso.FileExists(otaAttachment.FileName)) Then
fso.CopyFile strPath, "c:\" & TDAttachmentName
DownloadAttachment = "c:\" & TDAttachmentName
Else
DownloadAttachment = strPath
End if
Else
DownloadAttachment = strPath
End if
Else
fnReportEvent micFail, "Failure in library function 'GetFolderAttachmentPath'", "Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'."
DowloadAttachment = "Empty"
End If
Set otaAttachmentFactory = Nothing
Set otaAttachment = Nothing
Set otaAttachmentList = Nothing
Set otaAttachmentFilter = Nothing
Set otaTreeManager = Nothing
Set otaSysTreeNode = Nothing
Set fso = Nothing
End Function
'===============================================================
'Upload a File to QC to a specific path
'===============================================================
Public Function UploadAttachment(TDFolderPath,sFilePath)
Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
Dim otaAttachment 'As TDAPIOLELib.Attachment
Dim otaAttachmentList 'As TDAPIOLELib.List
Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
Dim otaTreeManager 'As TDAPIOLELib.TreeManager
Dim otaSysTreeNode 'As TDAPIOLELib.SysTreeNode
Dim otaExtendedStorage 'As TDAPIOLELib.TreeManager
Dim fso
Dim strPath 'As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set otaTreeManager = QCUtil.TDConnection.TreeManager
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
Set otaAttachmentFactory = otaSysTreeNode.Attachments
Set ObjAttch = otaAttachmentFactory.AddItem(Null)
ObjAttch.FileName = sFilePath
ObjAttch.Type = 1
ObjAttch.Post
ObjAttch.Refresh
Set otaAttachmentFactory = Nothing
Set otaAttachment = Nothing
Set otaAttachmentList = Nothing
Set otaAttachmentFilter = Nothing
Set otaTreeManager = Nothing
Set otaSysTreeNode = Nothing
Set fso = Nothing
End Function
'===============================================================
'Delete a QC Attachment file
'===============================================================
Public Sub DeleteFolderAttachment(TDAttachmentName, TDFolderPath)
'Test Director TDAPIOLELib object variables
Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
Dim otaAttachment 'As TDAPIOLELib.Attachment
Dim otaAttachmentList 'As TDAPIOLELib.List
Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
Dim otaTreeManager 'As TDAPIOLELib.TreeManager
Dim otaSysTreeNode 'As TDAPIOLELib.SysTreeNode
Dim otaExtendedStorage 'As TDAPIOLELib.TreeManager
Dim strPath 'As String
Set otaTreeManager = QCUtil.TDConnection.TreeManager
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
Set otaAttachmentFactory = otaSysTreeNode.Attachments
Set otaAttachmentFilter = otaAttachmentFactory.Filter
otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & otaSysTreeNode.NodeID & "_" & TDAttachmentName & "'"
Set otaAttachmentList = otaAttachmentFilter.NewList
If otaAttachmentList.Count > 0 Then
otaAttachmentFactory.RemoveItem otaAttachmentList.Item(1).ID
Else
Reporter.ReportEvent micFail, "Failure in library function 'GetFolderAttachmentPath'", "Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'."
End If
No comments:
Post a Comment