Domino Code Fragment

Code Name*
ExportView
Date*
03/04/1999
Source (or email address if you prefer)*
Anonymous
IP address:.18.221.101.89
Description*
Type*
LotusScript
Categories*
File Input/Output, Reporting/Searching
Implementation:
None (plug and play)
Required Client:
(none)
Server:
(none)
Limitations:
Probably only works on Windows based systems.
Comments:
I use this all the time for export files.
Files/Graphics attachments (if applicable): Code:
Sub ExportView(pView As NotesView, pPathAndFileName As String, pDelimiter As String)
'TITLE:
'ExportView
'DEFINED IN:
'AMEX Miscellaneous Tools Library
'DESCRIPTION:
'This sub routine takes a view, a file path and name, and a delimeter then exports the view into the file. This is very helpful for sharing data with outside non-Notes Applications
'USAGE:
'Call ExportView(<View>, <PathAndFileName>, <Delimeter>)
'Where <View> is the view to export, <PathAndFileName> is the path and file name to write to, and <Delimiter> is the delimeter (or separator) IE: ","
'RETURN VALUE:
'N/A
'EXAMPLE:
'Dim session As New NotesSession
'Dim db As NotesDatabase
'Dim view As NotesView
'Set db = session.CurrentDatabase
'Set view = db.GetView("By\Product")
'Call ExportView(view, "c:\My Documents\MyExport.txt", Chr(9))
'
'******This will return a Tab (or Chr(9)) separated export file based on the By Product view in the current database
'AUTHOR:
'Craig Dennis--AiC--Wednesday, March 03, 1999
Dim doc As NotesDocument
Dim ExportLine As String
Dim LineCount As Integer

'Reset File Handles
Close
Reset

'Open the File Handle
ExportFile = Freefile
Open pPathAndFileName For Output As ExportFile

'Begin loop through the view
Set doc = pView.GetFirstDocument
While Not (doc Is Nothing)
'Initialize the export line
ExportLine = ""
'Use the ColumnValues property of the document as defined in NotesDocument. Returns what appears in the view.
Forall item In doc.ColumnValues
'Since this is the first line just add the text value
If ExportLine = "" Then
ExportLine = Trim(Cstr(item))
End If

'Just in case the view has a list displayed........Avoid the error. Lists should not be in views that are to be exported due to lists being dynamic.
If Not Isarray(item) Then
'Append the Export Line with the current text value
ExportLine = ExportLine & Trim(Cstr(item)) & pDelimiter
Else
'If it is an array just return the first item of the list
ExportLine = ExportLine & Trim(Cstr(item(0))) & pDelimiter
End If
End Forall
'Increment Counter
LineCount = LineCount + 1
'Update Status
Print "Exporting Line - " & Cstr(LineCount)
'Write line to the file handle
Print #ExportFile, ExportLine
'Get the next document
Set doc = pView.GetNextDocument(doc)
Wend
Print "Complete. " & Cstr(LineCount) & " documents exported to " & pPathAndFileName
'Reset File Handles

Close
Reset
End Sub