Programmatically create a shortcut for Lotus Notes
When used in a form action, this code from SearchDomino.com member Jon Urwin will invite users to click a button, browse for a file, and then insert a shortcut to that file in a rich-text field. This is ideal for items like a Lotus Notes discussion database, because it provides an easy way for users to create a pointer to a shared file.
When used in a form action, this code will invite users to click a button, browse for a file, and then insert a shortcut to that file in a rich-text field. This is ideal for items like a Lotus Notes discussion database, because it provides an easy way for users to create a pointer to a shared file.
This code is made up of Formula language for a form action, and a LotusScript agent that is called by the Formula script.
Formula language for the form action:
REM {Runs LotusScript agent, which prompts user to browse for file...}; REM {...saves the Shortcut, and passes back the filepath}; @Command([RunAgent];"(file shortcut)"); REM {inserts shortcut at insertion point of a Rich Text field}; @Command([EditInsertFileAttachment]; @Environment("fileshortcutpath"))
The LotusScript agent:
(called '(file shortcut)' in this example) Runtime: Agent list selection Target:None >>>>>>>>>>> >>>>>>>>>>>> Sub Initialize Dim ws As New notesuiworkspace Dim s As New notessession a = ws.openfiledialog(False,"Select file to link to") If Isempty(a) Then Exit Sub ' exit if user clicks Cancel ' else continue ' get filename fname = Strrightback(a(0),"",5) Set SH = CreateObject("WScript.Shell") ' Shortcut is actually stored in Windows Temp directory, ready for attaching into document DPath = SH.ExpandEnvironmentStrings ("%windir%" & "Temp") Set SC = SH.CreateShortcut(DPath & "Shortcut to " & fname & ".lnk") ' sets environment variable, to pass the filepath of the 'Shortcut, so it can be picked up by the formula language action button Call s.SetEnvironmentVar("fileshortcutpath",DPath & "Shortcut to " & fname & ".lnk") SC.TargetPath = SH.ExpandEnvironmentStrings(a(0)) SC.WorkingDirectory = SH.ExpandEnvironmentStrings("%windir%") SC.WindowStyle = 4 SC.Save End Sub >>>>>>>>>>> >>>>>>>>>>>>
A pseudo protocol is a very simple way to create a shortcut for a file. If you add a string that looks like the following, it becomes a clickable hyperlink to the file: file:\\servername\directory and path\filename.
Thierry S.
******************************************
I believe there are a couple of errors in this agent that I'd like to point out:
First, in the (file shortcut) agent, dpath=sh.expandenvironmentstrings("%windir%" & "temp") is incorrect. Instead, there should be a backslash with "temp" to read dpath=sh.expandenvironmentstrings("%windir%" & "\temp").
Also in the (file shortcut) agent, fname=strrightback(a(0,"",5) returned nothing, which may have been by design. But changing this to fname = strrightback(Strleftback(a(0),".",5), "\", 5) returns a file name.
Chris L.
******************************************
Thanks for the feedback, Thierry, although the drawbacks to the pseudo file protocol are originally what prompted me to develop this workaround.
For example, when using file:\\servername\directory and path\filename, there are often issues if there's a space in the filename. Also, I have had reports of Internet Explorer 7 users struggling to launch links created with this protocol.
Jon Urwin, tip author
Do you have comments on this tip? Let us know.
Related information from SearchDomino.com:
- Learning Guide: LotusScript
- Learning Guide: Formula language
- FAQ: LotusScript advice
- FAQ: Formula language advice
- Reference Center: LotusScript tips and resources
-
Reference Center: Formula language tips and resources
This tip was submitted to the SearchDomino.com tip library by member John Urwin. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.