About This Code
Brief Description:
Open Notes Document as XPage
Last Modified:
23 Feb 2010
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
'/**
' * Opens a NotesDocument as an XPage.
' * From <a href="http://openntf.org/projects/codebin/codebin.nsf/CodeByDate/B2273FDFB3ABB485862576D300733C4F?OpenDocument">OpenNTF.org Code Bin</a>.
' * @param db NotesDatabase where the XPage (and presumably the document) resides.
' * @param strXPageName String name of the XPage, not including ".xsp" at the end.
' * @param strUNID Universal ID of the document. Can be blank for no document.
' * @param bNotes True if it should open within the Notes client, False if the XPage should open within the default web browser.
' * @param bEditMode True the XPage should open in edit mode, False if the XPage should open in read mode.
' */
Sub OpenDocAsXPage(db As NotesDatabase, ByVal strXPageName As String, ByVal strUNID As String, ByVal bNotes As Boolean, ByVal bEditMode As Boolean)
Dim ws As New NotesUIWorkspace
Dim astrURL(9) As String
If bNotes Then
astrURL(0) = "notes://"
Else
astrURL(0) = "http://"
End If
If db.Server <> "" Then
Dim nn As New NotesName(db.Server)
astrURL(1) = nn.Common
End If
astrURL(2) = "/"
astrURL(3) = db.FilePath
astrURL(4) = "/"
astrURL(5) = strXPageName
astrURL(6) = ".xsp?"
If bNotes Then
astrURL(7) = "OpenXPage&"
End If
If strUNID <> "" Then
If bEditMode Then
astrURL(8) = "action=editDocument&documentId="
Else
astrURL(8) = "action=readDocument&documentId="
End If
astrURL(9) = strUNID
End If
ws.URLOpen(Join(astrURL, ""))
End Sub
Usage / Example
Let's say you have documents in a classic Notes view in the client that you want opened as an XPage in edit mode. You can do it with this PostOpen event script:
Sub Postopen(Source As Notesuidocument)
Dim session As New NotesSession
Dim strUNID As String
Const XPAGE_NAME = "Order"
If Not Source.IsNewDoc Then strUNID = Source.Document.UniversalID
OpenDocAsXPage session.CurrentDatabase, XPAGE_NAME, strUNID, True, Source.EditMode
Source.Close
End Sub
This sample code only works for 8.5.1 and later because it will open the XPage within the Notes client. To open it as a web page instead, OpenDocAsXPage's fourth argument would need to be False.