Be able to use a Page or Form to enable end users to automatically launch any file types from network directory. Very useful when the design element does not have attachments to launch, rather looks for Network files to launch. The script will extract files to local temporary directory and launch them, thereby avoiding the netwwork files to be edited. The script will clean up all temp files on completion. I borrowed a function from searchDomino - Extract and start all attachments by Alexander Kogan, and tweaked slightly. (thanks and hope you don't mind).
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
This script essentially provides the ability to create a page with a series of hotspots pointing to files on the network. For example, I collated this process to enable persons to automatically launch Budget models in excel, policy documents in WordPro, etc. Each file location is stored in a keyword type document which is referenced by the Click routine.
Create a form, which may contain any number of hotspots designed to display files from the network. Do not want these files to be edited, rather view a copy of the document, leaving the Network directory file "as it was found".
1. Create a SaveOptions field, and set it to "0".
2. Do up your page, with tables, and Hotspots which state the files to view
3. Create a Rich Text Field called "Body"
4. Create a Computed, Multivalue value field: separated by (, ;) and display NewLine, called filePath. Value = filePath.
5. Create a Keyword Form - The form only needs FileName and FileLocation fields. - Name the Form "Document Location"
6. Create a view - File Locations - First sorted column (FileName), Second Column (FileLocation)
7. Create your Keyword documents - for FileLocation type in the full file path. Since script is being used, no need for (\) double backslashes
8. all this prevents hard coding of filepaths, etc...
9. Follow table instructions, to past Function and Declarations in the Globas of the Form
10. For each hotspot, Copy the Click command at the table. This will locate your filePath, attach the file to body field of your Form, then it will extract it to C:temp, then
the Function (kindly borrowed - slightly tweaked - from searchDomino - Extract and start all attachments by Alexander Kogan ) will launch the File.
May launch as many files as you wish. Each filePath will be appended to the filePath field.
11. The queryclose event, will trigger the Simple Agent to delete document.
12. Need to run another agent to clean up c:temp. This agent will loop through each string entry in filepath to delete all instances of the extracted files.
1. In the Global of the form - Option = Option Public
2. In Global of the Form - Declarations =
Declare Function SleepEx Lib "kernel32" Alias "SleepEx" (Byval dwMilliseconds As Long, Byval bAlertable As Long) As Long 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
3. In the Options of the Form, paste this:
Function ExtractAndView(Doc As NotesDocument) On Error Goto ErrorExtractAndStartAttchments Dim item As notesitem If Doc.HASEMBEDDED = True Then Forall eItem In Doc.ITEMS If (eItem.Type = Clng(RICHTEXT)) Then If Not (Isempty(eItem.EMBEDDEDOBJECTS)) Then Forall fItem In eItem.EMBEDDEDOBJECTS If fItem.Type = EMBED_ATTACHMENT Then Call fItem.EXTRACTFILE( "C:Temp" & fItem.Name) 'store this value to kill the file later "Inserted to create a string array in 'fielPath field" Set item = doc.GetFirstItem("filePath") Call item.AppendToTextList(fItem.Name) ret = ShellExecute(handle&, "open", "C:Temp" & fItem.Name, "", "", 1&) xx = SleepEx (4000,0) Doevents 'Exit Forall ' Only First attachment End If End Forall End If End If End Forall End If ExitExtractAndStartAttchments: Exit Function ErrorExtractAndStartAttchments: Msgbox ("in ExtractAndView: " + Error$(Err)) Resume ExitExtractAndStartAttchments End Function ==================================================== In the Query Close of the Form @Command([ToolsRunMacro];"delete uidoc"); @Command([toolsRunMacro];"kill") ==================================================== Create an agent - "delete uidoc" Simple Action - Delete Document Manually from the actions menu Selected Documents ==================================================== Create another agent "kill" Manually from the actions menu Selected Documents Sub Initialize Dim session As NotesSession Set session = New NotesSession Dim doc As NotesDocument Set doc = session.DocumentContext Dim path As Variant Dim DelFiles As Variant delFiles = doc.GetItemValue("filePath") Forall files In delFiles path = "C:Temp" & files Msgbox path Kill path End Forall End Sub
For each hotspot:
Sub Click(Source As Button) Dim ws As New notesuiworkspace Dim uidoc As notesuidocument Set uidoc = ws.currentdocument Dim doc As notesdocument Set doc = uidoc.document Dim filePath As String Dim view As notesview Dim lup As notesdocument Dim s As New notessession Dim db As notesdatabase Set db = s.currentdatabase Set view = db.getview("File Locations") Set lup = view.getdocumentbykey("Corporate Financial Guidelines") filePath = lup.FileLocationScript(0) Dim rtitem As Variant Dim file As notesrichtextitem Dim object As NotesEmbeddedObject 'insert the attachment before launching Set file = New NotesRichTextItem( doc, "Body" ) Set object = file.EmbedObject _ ( EMBED_ATTACHMENT, "", filePath) Call doc.save (True,True) uidoc.reload 'bring the attachment to screen Call ExtractAndView(Doc) Call uidoc.Save End Sub