Tuesday, September 21, 2010

Downloading an attachment from the Test Resource Module in Quality Center 10.

I've been looking for a solution to how to download a file from the Test Resource module in QC10 and finally came up with a solution. This function will download the specified filename from a specific resource name. It will output this file to the path specified.





'''
''' Retrieves a resource from the Test Resource Module
'''
''' The resource name
''' The file name of the resource
''' The path to which to save the resource
''' Path including filename of the resource on the local filesystem.
Public Function GetAttachmentFromResource(ByVal ResourceName, ByVal FileName, ByVal OutPath)
Dim strRetVal
strRetVal = ""

Dim TDConnection
Set TDConnection = QCUtil.QCConnection

Dim ResourceFactory
Set ResourceFactory = TDConnection.QCResourceFactory

Dim ResourceFilter
Set ResourceFilter = ResourceFactory.Filter
ResourceFilter.Filter("RSC_NAME") = ResourceName
ResourceFilter.Filter("RSC_FILE_NAME") = FileName

Dim ResourceList
Set ResourceList = ResourceFactory.NewList(ResourceFilter.Text)

Dim intCount
intCount = ResourceList.Count

If intCount = 1 Then
ResourceList.Item(1).DownloadResource OutPath, True

strRetVal = OutPath & "\" & FileName
Else
Reporter.ReportEvent micWarning, "Multiple Resources Found", "There were " & intCount & " resources when looking for the resource named """ & ResourceName & """ with the filename """ & FileName & """."
End If
Set ResourceList = Nothing
Set ResourceFilter = Nothing
Set ResourceFactory = Nothing
Set TDConnection = Nothing

GetAttachmentFromResource = strRetVal
End Function

3 comments:

Unknown said...

Do we have to have PRoject Administrator or Site Administrator access to run this code?

Percy Bell said...

You need the ability to run OTA code against QC and have access with that user to the attachments.

NG said...

How to download resources like libraries, object repositories and recovery scenarios from Particular folder under root folder from Quality center?