I've always found it frustrating that I have to use unattractive, inflexible action buttons to link to reports that have been uploaded to the TM1 Applications folder.
Hence, I'm attempting to develop a solution that will do this from regular hyperlinks in Excel. I've got the technology in place, but can't seem to work out the API code to call GetBlob in VB.NET.
Part 2 of my problem is that I don't know how to link the Applications folder path (eg, Finance/P&L.xls) to the Blob name in TM1 (eg P&L.xls_20080627091213.xls).
When I'm done I'll happily post the solution to the forum for all to share.
My code follows the post. Thanks in advance for any advice.
Harvey.
Here's the code. Note that some functions are omitted for brevity, but have been used in many other functions and are working correctly.
Code: Select all
Public Declare Function TM1BlobGet Lib "tm1api.dll" (ByVal hUser As Integer, ByVal hBlob As Integer, ByVal x As Integer, ByVal n As Integer, ByVal buf As String) As Integer
' Note: I have tried StringBuilder instead of String above and still get the same error
Public Function BlobGetData(ByVal hUser As Integer, ByVal strServerName As String, ByVal strBlobName As String, ByVal intBlobOffset As Integer, ByVal intMaxBytes As Integer) As String
            Dim hPool As Integer
            Dim hHandle As Integer
            Dim hBlobName As Integer
            Dim hBlob As Integer
            Dim hObject As Integer
            Dim hReturn As Integer
            Dim strBuffer As String
            Try
                hPool = GetPoolHandle() 
                hHandle = GetServerHandle(hPool, hUser, strServerName) 
                hBlobName = TM1ValString(hPool, strBlobName, 250)
                If CheckForAPIError(hUser, hBlobName) <> 0 Then Exit Try 
                hBlob = TM1ObjectListHandleByNameGet(hPool, hHandle, TM1ServerBlobs(), hBlobName)
                If CheckForAPIError(hUser, hBlob) <> 0 Then Exit Try
                hReturn = TM1BlobOpen(hPool, hBlob)
                If TM1ValBoolGet(hUser, hReturn) <> 1 Then
                    _ErrorString = "Could not open the blob"
                    Exit Try
                End If
                TM1BlobGet(hUser, hBlob, intBlobOffset, intMaxBytes, strBuffer)
                ' *** Note: The above function call fails with a NullReferenceException and no further information
                hReturn = TM1BlobClose(hPool, hBlob)
                If TM1ValBoolGet(hUser, hReturn) <> 1 Then
                    _ErrorString = "Could not close the blob"
                    Exit Try
                End If
            Catch ex As Exception
                _ErrorString += vbCrLf & "Error in BlobGetData: " & ex.ToString
            Finally
                If hPool <> 0 Then TM1ValPoolDestroy(hPool)
            End Try
            Return strBuffer
        End Function
