Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


pwaddles

113 posts

Master Geek


#16714 24-Oct-2007 14:25
Send private message

Im in the last few stages of building a website for a client.  The website takes orders online for glasses lenses, theres a lot of data that needs to be entered for each order.  At present I write the data to a database, but I need a way of sucking out all new orders to either 1 big txt file or seperate txt files.  I can make this work but it makes the files at the server end, I need the client to be able to download this file(s) to a local machine so his machinery can suck in the data and start processing.

Any thoughts?

Ive been using VB mostly for my scripts as its normally very easy to work with, and been using visual studio 2008 as my IDE.  Dont mind using any other languages but would rather stay on the micro$oft path as I doubt my host will allow PHP and VB.  Also keep in mind at present I read a record from the database in my VB script, then write it to a file, then get the next record etc...

Thanks to anyone who can help!


Create new topic
chakkaradeep
799 posts

Ultimate Geek

Trusted

  #92219 24-Oct-2007 14:36
Send private message

pwaddles: Im in the last few stages of building a website for a client. The website takes orders online for glasses lenses, theres a lot of data that needs to be entered for each order. At present I write the data to a database, but I need a way of sucking out all new orders to either 1 big txt file or seperate txt files. I can make this work but it makes the files at the server end, I need the client to be able to download this file(s) to a local machine so his machinery can suck in the data and start processing.

Any thoughts?


Read all the data from the database, put it in a CSV format and let the Client download it. He can then open that CSV file in Excel or open office :)




Regards,
Chaks

Desktop : Intel Quad Core Q9400 2.66GHz - 8GB RAM - 500 GB + 500 GB HDD - NVidia GeForce 9800GT - LG246WH Flatron Display - Windows Server 2008 R2 Enterprise with Hyper-V
Virtual Machine : Powered by Hyper-V and VMWare Workstation
Laptop: HP dv7-3004TX Entertainment Notebook PC | HP Touchsmart tx2 1119au - Windows 7 Ultimate x64
Mac: iMac 21.5" Snow Leopard
Mobile : iPhone 3GS



chakkaradeep
799 posts

Ultimate Geek

Trusted

  #92221 24-Oct-2007 14:38
Send private message

pwaddles:
Ive been using VB mostly for my scripts as its normally very easy to work with, and been using visual studio 2008 as my IDE. Dont mind using any other languages but would rather stay on the micro$oft path as I doubt my host will allow PHP and VB. Also keep in mind at present I read a record from the database in my VB script, then write it to a file, then get the next record etc...


What about ASP.NET ? Thats more coomfortable and has so many ways that you could handle building websites




Regards,
Chaks

Desktop : Intel Quad Core Q9400 2.66GHz - 8GB RAM - 500 GB + 500 GB HDD - NVidia GeForce 9800GT - LG246WH Flatron Display - Windows Server 2008 R2 Enterprise with Hyper-V
Virtual Machine : Powered by Hyper-V and VMWare Workstation
Laptop: HP dv7-3004TX Entertainment Notebook PC | HP Touchsmart tx2 1119au - Windows 7 Ultimate x64
Mac: iMac 21.5" Snow Leopard
Mobile : iPhone 3GS

pwaddles

113 posts

Master Geek


  #92224 24-Oct-2007 14:58
Send private message

I would've rather done it in ASP.NET but here I am knee deep in VB lol

how would I go about putting it into CSV format and letting the client download it?  I like the idea but need a few pointers to get it going.  Cheers



chakkaradeep
799 posts

Ultimate Geek

Trusted

  #92225 24-Oct-2007 15:02
Send private message

pwaddles: I would've rather done it in ASP.NET but here I am knee deep in VB lol

how would I go about putting it into CSV format and letting the client download it? I like the idea but need a few pointers to get it going. Cheers


What we do is with an aspx page,

1) Remove all html formatting
2) Read data from the datbaase
3) Response.Write values separated by commas
4) So, now if you load it in browser, and choose to see View Source, it will be of comma separated values
5) You could now redirect http://<domain>.aspx/file.csv to this page which if opened in IE will prompt for opening in Excel
6) Since the page doesnt have any html formatting and just has comma separated values, Excel will render without any problems

Of course, you need to have proper permissions set




Regards,
Chaks

Desktop : Intel Quad Core Q9400 2.66GHz - 8GB RAM - 500 GB + 500 GB HDD - NVidia GeForce 9800GT - LG246WH Flatron Display - Windows Server 2008 R2 Enterprise with Hyper-V
Virtual Machine : Powered by Hyper-V and VMWare Workstation
Laptop: HP dv7-3004TX Entertainment Notebook PC | HP Touchsmart tx2 1119au - Windows 7 Ultimate x64
Mac: iMac 21.5" Snow Leopard
Mobile : iPhone 3GS

pwaddles

113 posts

Master Geek


  #92232 24-Oct-2007 15:10
Send private message

cheers for that, ill give it a lash

nate
6473 posts

Uber Geek

Retired Mod
Trusted
Lifetime subscriber

  #92306 24-Oct-2007 21:53
Send private message

Adding to what chakkaradeep has already said, write all your data out using Response.Write, then set Response.Type of that page to "text/csv" and then have a Response.End.  Since this will be a text file put vbCrLf at the end of each line rather than <br>.

Link to the page such as http://www.myhost.co.nz/output.asp, and because of the Response.Type the browser will think it's a CSV file, and the user's default action for CSV files (such as open with Excel) will kick in.

This sorta stuff is really easy to do - great if your client wants to mail merge, do their own reports etc.

chakkaradeep
799 posts

Ultimate Geek

Trusted

#92308 24-Oct-2007 22:02
Send private message

nate: Adding to what chakkaradeep has already said, write all your data out using Response.Write, then set Response.Type of that page to "text/csv" and then have a Response.End. Since this will be a text file put vbCrLf at the end of each line rather than


Thanks nate, I knew I had missed something Laughing




Regards,
Chaks

Desktop : Intel Quad Core Q9400 2.66GHz - 8GB RAM - 500 GB + 500 GB HDD - NVidia GeForce 9800GT - LG246WH Flatron Display - Windows Server 2008 R2 Enterprise with Hyper-V
Virtual Machine : Powered by Hyper-V and VMWare Workstation
Laptop: HP dv7-3004TX Entertainment Notebook PC | HP Touchsmart tx2 1119au - Windows 7 Ultimate x64
Mac: iMac 21.5" Snow Leopard
Mobile : iPhone 3GS

 
 
 

Cloud spending continues to surge globally, but most organisations haven’t made the changes necessary to maximise the value and cost-efficiency benefits of their cloud investments. Download the whitepaper From Overspend to Advantage now.
pwaddles

113 posts

Master Geek


  #92316 24-Oct-2007 22:22
Send private message

I cant use Response.type, would it be called something else in VB?

cheers

Hadley

nate
6473 posts

Uber Geek

Retired Mod
Trusted
Lifetime subscriber

  #92317 24-Oct-2007 22:25
Send private message

Sorry it's been so long since I've used classic ASP

Try Response.ContentType="text/csv"

You should really look at switching to asp.net :)

pwaddles

113 posts

Master Geek


  #92319 24-Oct-2007 22:31
Send private message

cheers for that

so should this work?

--page called temp.aspx--

protected sub temp_load(byval .......)

   response.write(field1 & "," & field2 & "," & field3)

   response.contentype = "txt/csv"

   response.end()

   server.transfer("temp.aspx")

end sub

thanks for the prompt replies

chakkaradeep
799 posts

Ultimate Geek

Trusted

  #92320 24-Oct-2007 22:31
Send private message

nate: Sorry it's been so long since I've used classic ASP

Try Response.ContentType="text/csv"


Me too same. Its been soo long since I have used class ASP Smile

nate:
You should really look at switching to asp.net :)


I second that Cool




Regards,
Chaks

Desktop : Intel Quad Core Q9400 2.66GHz - 8GB RAM - 500 GB + 500 GB HDD - NVidia GeForce 9800GT - LG246WH Flatron Display - Windows Server 2008 R2 Enterprise with Hyper-V
Virtual Machine : Powered by Hyper-V and VMWare Workstation
Laptop: HP dv7-3004TX Entertainment Notebook PC | HP Touchsmart tx2 1119au - Windows 7 Ultimate x64
Mac: iMac 21.5" Snow Leopard
Mobile : iPhone 3GS

chakkaradeep
799 posts

Ultimate Geek

Trusted

  #92321 24-Oct-2007 22:34
Send private message

pwaddles: cheers for that

so should this work?

--page called temp.aspx--

protected sub temp_load(byval .......)

response.write(field1 & "," & field2 & "," & field3)

response.contentype = "txt/csv"

response.end()

server.transfer("temp.aspx")

end sub

thanks for the prompt replies


You have to set up the redirect link in IIS

The best way is to redirect 404 page not found error to this page which renders the CSV Laughing

So, if your domain is http://mydomain.co.nz,

http://mydomain.co.nz/data.csv would be page not found. You could redirect this 404 page not found error to http://mydomain.co.nz/temp.aspx Cool

So, now when users type http://mydomain.co.nz/data.csv they will get the CSV file Wink




Regards,
Chaks

Desktop : Intel Quad Core Q9400 2.66GHz - 8GB RAM - 500 GB + 500 GB HDD - NVidia GeForce 9800GT - LG246WH Flatron Display - Windows Server 2008 R2 Enterprise with Hyper-V
Virtual Machine : Powered by Hyper-V and VMWare Workstation
Laptop: HP dv7-3004TX Entertainment Notebook PC | HP Touchsmart tx2 1119au - Windows 7 Ultimate x64
Mac: iMac 21.5" Snow Leopard
Mobile : iPhone 3GS

nate
6473 posts

Uber Geek

Retired Mod
Trusted
Lifetime subscriber

  #92322 24-Oct-2007 22:35
Send private message

pwaddles: cheers for that

so should this work?

--page called temp.aspx--

protected sub temp_load(byval .......)

response.write(field1 & "," & field2 & "," & field3)

response.contentype = "txt/csv"

response.end()

server.transfer("temp.aspx")

end sub

thanks for the prompt replies


try this

protected sub temp_load(byval .......)

for i = 0 to itemscount 'do your loop here
   response.write(field1 & "," & field2 & "," & field3 & vbCrLf)
next

response.contentype = "txt/csv"
response.end()

end sub

One small issue with CSV is if any of your fields have a comma in them, it'll stuff up the whole file.  Best thing to do is to check if each value is a string, and if it is, surround if with "speech marks"

freitasm
BDFL - Memuneh
79253 posts

Uber Geek

Administrator
ID Verified
Trusted
Geekzone
Lifetime subscriber

#92323 24-Oct-2007 22:36
Send private message

Better still:


Response.ContentType = "application/vnd.ms-excel"
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1


Now create an output with TABLE.

Each column will be a TD, each row a TR.

When opening this file on the browser it will automatically open Microsoft Excel - and place each CELL in an apropriate cell.

This way you don't have to worry about comma in a CSV - you never know if your data will contain an actual comma and need some clean up, so this method is safer.




Please support Geekzone by subscribing, or using one of our referral links: Samsung | AliExpress | Wise | Sharesies | Hatch | GoodSyncBackblaze backup


nate
6473 posts

Uber Geek

Retired Mod
Trusted
Lifetime subscriber

  #92443 25-Oct-2007 19:05
Send private message

freitasm: Better still:


Response.ContentType = "application/vnd.ms-excel"
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1


Now create an output with TABLE.

Each column will be a TD, each row a TR.

When opening this file on the browser it will automatically open Microsoft Excel - and place each CELL in an apropriate cell.

This way you don't have to worry about comma in a CSV - you never know if your data will contain an actual comma and need some clean up, so this method is safer.


I never knew you could do this Mauricio, I spose you learn something new everyday!

Create new topic





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.