Can I use Webfile for this?

OK trying to figure out:

This creates a csv file that will be downloaded. The calling procedure will create the Recordset then Call this and then do showurl.

I have a function that creates a text cvs file.

Can I make tos as Webfile, a property of the window?

Not sure what to do?

DoCVS(rs as RecordSet)

dim tos as textOutputStream
dim s as string
dim i, j as integer

tos = lfFile.CreateTextFile


Dim lnEmailCol As Integer

for i = 1 to rs.FieldCount
s = s +rs.IdxField(i).Name + “”","""

for i=1 to rs.RecordCount 'for each row
s="""" 'build line to save
for j=1 to rs.FieldCount 'for each column
s = s + ChkStr(rs.IdxField(j).StringValue) + “”","""

rs.MoveNext 'save line


Yes, prepare your CSV entirely then put the string in the WebFile.Data property.

You’ll need to rewrite your code such that you’re not generating the CSV during the write operation. I would recommend this as a general best practice too.

It is possible to avoid messing around with String.Left if you construct the row as an array kind of like this:

dim rs as RecordSet = MySelect
dim tarsRows() as String

while not rs.EOF
  dim tarsThisRow() as String
  for i as Integer = 1 to rs.FieldCount

  next i

  // Build the row and append it to the complete data
  dim sThisRow as String = Join(tarsThisRow, ",")



// Generate the complete CSV from the rows
dim sCSV as String = Join(tarsRows, EndOfLine.Unix)

// Prepare the WebFile
moMyWebFileInstance.Data = sCSV

Notes about this code:

  • This was written in the forum post editor, corrections may be necessary
  • Depending on your data, you may need to apply quotes to a field
  • This is a really flimsy CSV generation method, there may be better options

Getting NilObjectException on

moMyWebFileInstance.Data = sCSV

Needed to instantiate it.

I zip every file I offer to download, except PDF (already compressed), so the browser doesn’t try to grab and display it.