Archived Content: This information is no longer maintained and is provided "as is" for your convenience.
Automatically opening a TRIM based document
Return to General Articles page
Your SDK based application has found a particular record. Now you want to open it using it’s native application so that the user can view or change it.
Some VB6 code
>>>> start of module1.bas Option Explicit Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Public Const SW_SHOWDEFAULT = 10 <<<< end of module1.bas
>>>> start of code snippet Const myDirectory = "C:\" ' for a particular record ' Set extractDoc = TRIMRecord.GetExtractDocument ' extractDoc.DoExtract myDirectory ' extractPath = myDirectory & extractDoc.FileName ' OR for a rendition ' extractPath = TRIMRecordRendition.Extract(myDirectory & TRIMRecordRendition.Description) ' OR a revision ' extractPath = TRIMRecordRevision.Extract(myDirectory & TRIMRecordRevision.Description) execReturn = ShellExecute(0, "Open", extractPath, "", myDirectory, SW_SHOWDEFAULT) If execReturn <> 42 Then MsgBox "Unexpected return code of " & execReturn & " from the shell execute!", vbCritical End If <<<< end of code snippet
What's this all do?
This project uses “shell execute” which is a Win API call. In VB Win API calls are usually defined “public” and therefore need to be defined in a separate module within the project. This is what the first code snippet is doing.
Now that “shellExecute” is defined we can use it to open a particular file.
The next snippet of code assumes that you have already identified the record or the particular rendition/revision you want to open. Uncomment the particular line(s) you need.
First we extract the attachment, this will load it onto the users PC, and return it’s full path name. Now do a shell execute, this tells Windows to open the extracted file using the correct program for it’s extension. It’s the same as if the user had found the extracted file using explorer and double clicked on it.
What can go wrong
Don’t forget to check your returns! If TRIM has some problem doing what you want it will return “null” and expect you to query the errormessage property.
The ShellEx will return a code indicating what happened, you can find what they mean by Googling. A return of 42 means success, anything else means that something went wrong.
Don’t forget that Windows is configured to use certain programs for certain extensions. If the user has told Windows to use Notepad to open “.doc” files, then.... well... there’s not a lot you can do about it.
Finally you should wrap this in an exception handler. Stuff happens!
Don’t forget that after you’ve kindly opened the file and the user has changed it you may need to checkin their changed version. This depends on your sites setup, ODMA compliant applications and/or programs that have a TRIM interface will handle that for you. Otherwise it maybe useful to use the Record objects SetAutoCheckin method.