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

>>>>>>>>>>>
>>>>>>>>>>>>

MEMBER FEEDBACK TO THIS TIP

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:

This was first published in February 2007

Dig deeper on LotusScript

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close