Examples

Creating a file and moving it to a specific location on the client computer

'	Notes Client
'		1. Create file in c:\tmp\ümläüt.xml
'		2. Write file contents
'	Nomad for Web Browsers:
'		1. Create file in the browser's virtual filesystem: vfs:/tmp/ümläüt.xml
'		2. Write file contents
'		3. Make vfs file available to the real filesystem (file in user's temp directory)
'		4. Use COM object to copy file to c:\tmp\ümläüt.xml
'		5. Unlink vfs file (delete's temp file)
'		6. Delete original vfs:/tmp/ümläüt.xml
Sub Click(Source As Button)
	On Error Goto HandleError 
	
	Dim session As New notesSession
	Dim sPath As String
	If session.Platform = "WebBrowser" Then
		'Paths in the browser are like *nix paths with the vfs prefix
		sPath = "vfs:/tmp/ümläüt.xml"
	Else
		sPath = "c:\tmp\ümläüt.xml"
	End If
	
	Dim nFile As Integer
	nFile = Freefile
	Open sPath For Output As nFile
	Print #nFile, "<TestData></TestData>"
	Close nFile
	
	' Keep track of call to FileOpBegin for this file to clean up later
	Dim fSFOB As Boolean 
	
	If session.Platform = "WebBrowser" Then
		session.FileOpBegin sPath, True
		fSFOB = True
		Dim fso As Variant
		Set fso = CreateObject("Scripting.FileSystemObject")
		' COM Helper will translate sPath used in FileOpBegin to the temp file location
		' Do not remove/move the temp file except through calling FileOpEnd. These instructions should be paired.
		fso.CopyFile sPath, "c:\tmp\ümläüt.xml"
	End If
	
Finally:
	On Error Goto HandleFinallyError
	If fSFOB Then
	 	' Clean up the temp file on the native fs before cleaning up the vfs file
		' Note: Calling session.FileOpBegin on more than one file in a body of script will require more complex 
		' logic than is shown here (a simple flag) to clean up.
		session.FileOpEnd sPath	
		If nFile > 0 Then
			Kill sPath ' Clean up vfs file
		End If
	End If
	Exit Sub
	
HandleFinallyError:
	Msgbox "Error  - " & sPath & " - " & nFile & " - " & Error &" at line number  " & Erl
	Exit Sub
	
HandleError:     
	Msgbox "Error  - " & sPath & " - " & nFile & " - " & Error &" at line number  " & Erl
	Resume Finally 	
End Sub

Using Excel to create a spreadsheet and attaching it to a document

'	Notes Client
'		1. Use excel to populate a spreadsheet
'		2. Save the file to a location on the native filesystem: c:\tmp\ümläüt.xlsx
'         	3. Attach the file to a document.
'		4. Delete file in the native filesystem
'	Nomad for Web Browsers:
'		1. Use excel to populate a spreadsheet
'		2. Save the file to a location on the native filesystem: c:\tmp\ümläüt.xlsx
'		3. Import file to the virtual filesystem: vfs:/tmp/ümläüt.xlsx
'		4. Attach the file to a document.
'		5. Delete file in the virtual filesystem
Sub Click(Source As Button)
	On Error Goto HandleError 
	
	Dim session As New notesSession
	Dim sPath As String
	If session.Platform = "WebBrowser" Then
		'Paths in the browser are like *nix paths with the vfs prefix
		sPath = "vfs:/tmp/ümläüt.xlsx"
	Else
		sPath = "c:\tmp\ümläüt.xlsx"
	End If
	
	' Keep track of call to FileOpBegin for this file to clean up later
	Dim fSFOB As Boolean 
	
	If session.Platform = "WebBrowser" Then
		session.FileOpBegin sPath, False ' file does not exist (yet)
		fSFOB = True
	End If
	
	Dim excelApp As Variant
	Set excelApp = CreateObject("Excel.Application")
	Call excelApp.Workbooks.add 'to create new worksheet
	
	' Write out headings
	excelApp.Cells(1, 1).value = "Name"
	excelApp.Cells(1, 2).value = "SSN"
	excelApp.Cells(1, 3).value = "DOB"
	excelApp.Cells(1, 4).value = "Address"
	
	' Write out data
	excelApp.Cells(2, 1).value = "John Doe"
	excelApp.Cells(2, 2).value = "123-45-6789"
	excelApp.Cells(2, 3).value = "01/01/2001"
	excelApp.Cells(2, 4).value = "1313 Mockingbird Lane / Mockingbird Heights, CA 90046"
	
	' COM Helper will translate sPath used in FileOpBegin to the temp file location
	Call excelApp.Workbooks(1).SaveAs(sPath)
	Call excelApp.Workbooks.Close ' release the file lock excel is holding
	
	If session.Platform = "WebBrowser" Then
		session.FileOpEnd sPath ' import file into virtual filesystem
		fSFOB = False ' we just handled this, so we won't need to clean this up later
	End If
	
	Dim db As NotesDatabase
	Set db = session.CurrentDatabase
	
	Dim doc As NotesDocument
	Set doc = New NotesDocument(db)
	
	doc.Form = "File"
	doc.Title = sPath
	
	Dim rti As NotesRichTextItem
	Set rti = doc .CreateRichTextItem("FileAttachment")
	Call rti.EmbedObject(EMBED_ATTACHMENT, "", sPath)
	
	Call doc.Save(True, False)
	
Finally:
	On Error Goto HandleFinallyError
	Call excelApp.Quit	
	If fSFOB Then
	 	' Clean up the temp file on the native fs before cleaning up the vfs file
		' Note: Calling session.FileOpBegin on more than one file in a body of script will require more complex 
		' logic than is shown here (a simple flag) to clean up.
		session.FileOpEnd sPath
	End If
	Kill sPath ' delete the file that was attached
	
	Exit Sub
	
HandleFinallyError:
	Msgbox "Error  - " & sPath & " - " & nFile & " - " & Error &" at line number  " & Erl
	Exit Sub
	
HandleError:     
	Msgbox "Error  - " & sPath & " - " & nFile & " - " & Error &" at line number  " & Erl
	Resume Finally 	
End Sub

Using Excel to create a spreadsheet at a specific location on the computer

'	Notes Client
'		1. Use excel to populate a spreadsheet
'		2. Save the file to a location on the filesystem: c:\tmp\ümläüt.xlsx
'	Nomad for Web Browsers:
'		1. Use excel to populate a spreadsheet
'		2. Save the file to a location on the filesystem: c:\tmp\ümläüt.xlsx
'
'	As you can see, there is no need for any Nomad specific code here if you are not handling
'	the file with Nomad at all.  Programs accessed via COM can access the native filesystem.
Sub Click(Source As Button)
	On Error Goto HandleError 
	
	Dim session As New notesSession
	Dim sPath As String
	sPath = "c:\tmp\ümläüt.xlsx"
	
	Dim excelApp As Variant
	Set excelApp = CreateObject("Excel.Application")
	Call excelApp.Workbooks.add 'to create new worksheet
	
	' Write out headings
	excelApp.Cells(1, 1).value = "Name"
	excelApp.Cells(1, 2).value = "SSN"
	excelApp.Cells(1, 3).value = "DOB"
	excelApp.Cells(1, 4).value = "Address"
	
	' Write out data
	excelApp.Cells(2, 1).value = "John Doe"
	excelApp.Cells(2, 2).value = "123-45-6789"
	excelApp.Cells(2, 3).value = "01/01/2001"
	excelApp.Cells(2, 4).value = "1313 Mockingbird Lane / Mockingbird Heights, CA 90046"
	
	Call excelApp.Workbooks(1).SaveAs(sPath)
	Call excelApp.Workbooks.Close
	
Finally:
	On Error Goto HandleFinallyError
	Call excelApp.Quit	
	Exit Sub
	
HandleFinallyError:
	Msgbox "Error  - " & sPath & " - " & nFile & " - " & Error &" at line number  " & Erl
	Exit Sub
	
HandleError:     
	Msgbox "Error  - " & sPath & " - " & nFile & " - " & Error &" at line number  " & Erl
	Resume Finally 	
End Sub