
So you've made your form all nice looking, everything fits nicely in tables, etc., but when users add file attachments, it goes all out the window. This is a Better Waytm to do things. On the input side, you either have your normal rich text field, or your File Upload Control for the web. Use your $V2AttachmentOptions field set to "0", and hide the rich text field so at least on the read side, the attachments are hidden. Next, I do a ComputedText field set to @Implode (@AttachmentNames; " ") so you can show the file attachments in a nice list.
Next, setup a new form or subform. This will be called by an @DialogBox in the LotusScript. I usually create a small layout region, give it the 3d effect. Place one field in it, called ChosenAttachment and make it a Dialog List. The Choice List for the field will be @AttachmentNames. Make everything look nice, because that is what we do. Save the form as FileAttachList.
Create a button on your main form. I usually put something like this:
For the value of the button, change it to Script and paste the entire code section below.
What will happen, is when you are viewing the document in read mode, you click the button, and up pops a dialogbox listing all the file attachments on the form. You select one, hit OK. It will launch the file attachment, as long as a file handler is defined by the system itself. If you have a ".QXY" attachment, and your system doesn't know what to do with it, don't expect Notes to magically know.
OH, BTW, Win32 only. Doesn't work on the web either. Watch for lines wrapping too, you might have to paste them back together.
-------- Cut Here --------
' Please create a form or subform called FILEATTACHLIST
' On the subform, create a Dialog List field called CHOSENATTACHMENT
' The values of the choices would be a Formula of @AttachmentNames
' Then, put this button on your main form.
' This script is coded to run through the attachments in the field "Comments"
Sub Click(Source As Button)
Dim session As New notessession
Dim ws As New notesuiworkspace
Dim db As notesdatabase
Dim view As notesview
Dim doc As notesdocument
Dim rtItem As notesrichtextitem
Dim x As Integer
Dim targetpath As String
Dim path As String
Dim n as Variant
targetpath = "c:\temp\"
ispathavailable (targetpath)
Set db = session.currentdatabase
Set doc = ws.currentdocument.document
success = ws.dialogbox ("fileattachlist", True, True, False, False, False, False, "Choose Attachment", doc)
If (success = False) Then
Exit Sub
End If
path = targetpath & Cstr(doc.chosenattachment(0))
Set n = doc.GetAttachment(cstr(doc.chosenattachment(0)))
Call n.ExtractFile(path)
Call DoWithFileAndApp(path,"open")
End Sub
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
Function DoWithFileAndApp(fName As String, Action As String) As Long
Dim hwnd As Long
Dim fAction As Long
Select Case Ucase(Action)
Case Ucase("open") : fAction = 0
Case Ucase("print") : fAction = 7
End Select
R& = ShellExecute(hwnd,Action, fName, "","",fAction)
End Function
Function IsDriveAvailable(drivNam$) As Variant
'// Does Drive exists
'// Called by : Function IsPathAvailable, Function DetachAll
'// Calls : none
On Error Goto Errors
IsDriveAvailable = False
If Dir$(drivNam, 8) <> "" Then
IsDriveAvailable = True
End If
TheEnd:
Exit Function
Errors:
Resume TheEnd
End Function
Function IsPathAvailable(path As String) As Variant
'// Determine if a path exist; if not create path
'// Called by : Function DetachAll
'// Calls : Function IsDriveAvailable
Dim session As New NotesSession
Dim MyPath$, tmpPath$
Dim result%, pos%
On Error Resume Next
If IsDriveAvailable(Left(path,3)) Then
Chdrive Left( path, 1 )
Chdir path
result = False
pos = 1
If Curdir + "\" <> path Then
If Right( path, 1 ) <> "\" Then path = path + "\"
If path = "" Then Goto Exit_CheckDir
Chdrive Left( path, 1 )
Do While pos <> 0
pos = Instr( pos, path, "\" )
If pos > 0 Then
tmpPath = Left( path, pos-1 )
Mkdir tmpPath
Chdir tmpPath
pos = pos + 1
End If
Loop
If Curdir + "\" = path Then
result = True
End If
Else
result = True
End If
Else
End If
Exit Function
Exit_checkDir:
IsPathAvailable = result
Exit Function
End Function