Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - db to .csv and download
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

db to .csv and download

 Post Reply Post Reply
Author
Dan H View Drop Down
Newbie
Newbie


Joined: 17 September 2006
Location: United States
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dan H Quote  Post ReplyReply Direct Link To This Post Topic: db to .csv and download
    Posted: 01 May 2007 at 2:18am
I'd like to create (on demand) a .csv file from records in my db, then download the file to the client.
I think it would go like this:
(collect variables in asp, then)

set fs=server.createobject("scripting.filesystemobject")
set f=fs.createtextfile(server.mappath("/test.csv"),true)
f.writeline("<%=value1%>" & "," & "<%=value2%>")
f.writeline("<%=value3%>" & "," & "<%=value4%>")
f.close
<a href="http://www.mysite.com/test,csv">Download</a>

Does this make any sense?
Is there a cleaner way to do it?
I should probably create a unique name for the file to keep somebody from creating the file, then letting the link sit on their browser for awhile- they could get someone elses file.
I'd have to delete it after download.
How would I do that?
Thanks for any thoughts.
Dan

Back to Top
kbannon View Drop Down
Groupie
Groupie


Joined: 03 October 2002
Location: Ireland
Status: Offline
Points: 115
Post Options Post Options   Thanks (0) Thanks(0)   Quote kbannon Quote  Post ReplyReply Direct Link To This Post Posted: 01 May 2007 at 12:15pm
You are writing one record on two lines - is that intentional?

After you have:
set fs=server.createobject("scripting.filesystemobject")
set f=fs.createtextfile(server.mappath("/test.csv"),true)
you should set up a recordset and loop through the records with each iteration of the loop writing to the csv file.
After the loop has finished you close the recordset & connection and then close 'f'
To save the file with a unique name just include the date in the filename?

See http://www.webdeveloper.com/forum/archive/index.php/t-34898.html  for a bit more.
I don't suffer from insanity, I enjoy every minute of it.
Back to Top
Dan H View Drop Down
Newbie
Newbie


Joined: 17 September 2006
Location: United States
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dan H Quote  Post ReplyReply Direct Link To This Post Posted: 01 May 2007 at 2:07pm
Ok- that's what I was thinking.
Thanks.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.