Editing attachment directly-postopen event

Hello All,

i am opening one document and that document is having the attachment on it…

can anybody let me that how can write the code that open the attachment(PostOpen) and closes current opened document.

first it will open the attachment and 'would close the current opened document.

any help will be appriciated.

Dev

Subject: Editing attachment directly-postopen event

Look at the Microsoft Office template ( doclbm7.ntf ). This application does what you are looking for. I have used this for base in many similar type notes databases.

Subject: Editing attachment directly-postopen event

Built into your form is the Auto-Launch feature (3rd tab on form properties)

One of the options is “-First Attachment-”

If this doesn’t work for you, please let me know and explain what you’d like that is different.

:slight_smile:

Subject: RE: Editing attachment directly-postopen event

It is not opening though it is in edit mode and i have enabled form property for first attachment

any help pls

Dev

Subject: RE: Editing attachment directly-postopen event

Hmmmm, very interesting :slight_smile:

What kind of attachment is it, what application created it … the extension?

If this file resides in a folder on the pc and that same user double mouseclicks on it… does it open with the application that wrote it?

Solving this would be the preferred method… otherwise, Plan B would include saving the attached file to a local path then query the windows registry for the application’s path and shell out to launch it with this filename as an added parameter.

PLAN B:

Here is an example - assuming you’ve already removed the attachment before calling this sub. Would you like assistance with code that does the first part (not included)?

Sub launchFile(FilePath As String)

Print “Launching attachment…”

Dim taskID%

taskID% = ShellExecute( 0, “Open”, FilePath, “”, “”, 0)

If taskID% < 32 Then

Dim newTaskID%

newTaskID% = Shell("rundll32.exe shell32.dll, OpenAs_RunDLL " & FilePath, 0)

End If

End Sub

Subject: RE: Editing attachment directly-postopen event

File would be microsoft word .doc extension or excel file (.xls)

Please assist.!!!

Dev

Subject: RE: Editing attachment directly-postopen event

fine… here is the code.If you are opening the UIDOC in edit mode, you’ll need to create a hidden text editable field called SaveOptions. It doesn’t need any default value not anything in it…it just must be there so we can close the uidoc without asking the user if they want to save their changes (which there won’t be any need to ask).

Paste this entire snippet into Declarations and it will move itself into the proper locations automatically.

Sub launchFile(FilePath As String)

Print “Launching attachment…”

Dim newTaskID As Integer

newTaskID% = Shell("rundll32.exe shell32.dll, OpenAs_RunDLL " & FilePath, 0)

End Sub

Sub Postopen(Source As Notesuidocument)

Dim s As New NotesSession

Dim db As NotesDatabase

Set db = s.currentdatabase

Dim uidoc As NotesUIDocument

Dim w As New NotesUIWorkspace

Set uidoc = w.currentdocument

Dim backendDoc As NotesDocument

Set doc = uidoc.Document

Dim object As NotesEmbeddedObject

If Not ( doc Is Nothing ) Then 'prevents code running on new doc

filenames=Evaluate(“@AttachmentNames”,doc)

numberoffiles=Evaluate(“@Attachments”, doc)

If numberoffiles(0)> 0 Then

For filecounter=0 To numberoffiles(0)-1

Print filenames(filecounter)

Set object = doc.GetAttachment( filenames(filecounter) )

If ( object.Type = EMBED_ATTACHMENT ) Then

fileCount = fileCount + 1

Call object.ExtractFile(Left((Trim(s.getEnvironmentString(“Directory”, True))),3) & filenames(filecounter) ) ’

Call launchFile(filenames(filecounter))

End If

Next filecounter

Msgbox "Total Files Detatched: " & Cstr(fileCount)

Call uidoc.FieldSetText(“SaveOptions”,“0”)

Call uidoc.Close(True)

End If

End If

End Sub

Let me know if you have any questions or problems.

:slight_smile:

(just made small edit to fix typo)