Programmatically create a shortcut for Lotus Notes

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};

The LotusScript agent:

(called '(file shortcut)' in this example)
Runtime: Agent list selection

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 =
SC.WindowStyle = 4
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.

    This was first published in February 2007

  • There are Comments. Add yours.

    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    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:

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.