Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV EXPORT IN ASP

Status
Not open for further replies.

gsc123

Programmer
Jan 24, 2008
197
Hi

Is it possible to do a command line instruction to export from a table in ASP>
 

Command line? Don't know what you mean, but here's how you can write to a file on a web server. Location has to have write permissions enabled. Also, you might have to filter out various end of line/carriage return characters out of your data. E.g., vbcrlf, <br>, ...


dim filename, source, address, sql, rsTable1, fileobj, thefile, line
filename = "whatever.csv"
source = "/some_address/" & filename
address = Server.MapPath(source)

sql = "SELECT field1, field2, ... "
sql = sql + "FROM table1 ... "
set rsTable1 = Server.CreateObject("ADODB.Recordset")
rsTable1.ActiveConnection = "yourconnectstring"
rsTable1.source = sql
rsTable1.Open()

set fileobj = Server.CreateObject("Scripting.FileSystemObject")

'Check for existing file if you want to
'if fileobj.FileExists(address) then
'
'else
'
'end if

set thefile = fileobj.CreateTextFile(address, true)

'first line is field names
thefile.WriteLine ("field1name" & vbTab & "field1name" ...)

while not rsTable1.EOF
line = replace(rsdetail("field1"), vbtab, "") & vbtab & replace(rsdetail("field2"), vbtab, "") & ...
thefile.WriteLine line
rsTable1.MoveNext()
wend

thefile.Close
set thefile = nothing
set fileobj = nothing

rsTable1.Close
set rsTable1 = nothing
[/code]
 
I'd like to export from a table in access to create a csv version
 
That is by a run command in asp
 
This does'nt really show me the command for exporting from ACCESS , is it not possible?
 
it certainly is possible to extract from Access to CSV via many methods, the references posted above were for a starting point in your exploration and development rather than giving you the answer on a plate especially as you did not specifically mention Access in your original question.

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
I see, well I know the command line shell, but not how to export from using it
 
gsc123:

The only part of your original question that is appropriate to this forum is, how to run a command from an ASP program. tsuji provided you with that answer.

For anything specific to Access, you would be better off asking in one of the many Access forums on this site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top