Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

save as CSV format

Posted on 2003-09-14
7
Medium Priority
?
335 Views
Last Modified: 2010-03-25
Hey guys,

Anyone have an idea on how to create a CSV file and have the user download it (save as file). I've done it in php, and I guess its also possible in ASP.

I've visited this thread, (http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20349406.html) and it just showed on how to create the csv. My question is, is it possible to have users see the save as/download this file when user clicks Download button? If it is, anyone can show me a sample code...
0
Comment
Question by:madeline448
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 20

Expert Comment

by:Michel Sakr
ID: 9360446
Hi madeline448,
something like:
<%
Response.ContentType = "application/vnd.ms-excel"

Response.AddHeader "Content-disposition", "attachment; filename=report" & Day(Date) & Month(Date) & 
Year(Date) & ".xls"

' contents here...
%>

----
The "attachment" attribute is a directive to the browser to save, not to show, the document. It doesn't
work with IE 4.01 as this browser has a bug with it (it's a RFC though). If you want the browser to
open the document by default, use "inline" instead.


http://support.microsoft.com/support/kb/articles/Q260/5/19.ASP

Cheers!
Michel
MCAD, MCSA, MCDBA
0
 
LVL 20

Accepted Solution

by:
Michel Sakr earned 800 total points
ID: 9360453
madeline448, the full code would be like
<%
strFileName = fileNameorpath
Response.ContentType = "application/vnd.ms-excel"
'Response.AddHeader "Content-disposition", "attachment; filename=" & strFileName & ".csv"
'un-comment the above line if you want to force the users to save the file, otherwise it will open in the browser if excel is installed
' contents here...

set objBinaryFile = Server.CreateObject("BinaryFileStream.Object")
Response.BinaryWrite objBinaryFile.GetFileBytes(CStr(strFileName))
set objBinaryFile = nothing

%>

----
The "attachment" attribute is a directive to the browser to save, not to show, the document. It doesn't
work with IE 4.01 as this browser has a bug with it (it's a RFC though). If you want the browser to
open the document by default, use "inline" instead.


http://support.microsoft.com/support/kb/articles/Q260/5/19.ASP


BinaryFileStream object dll can be found here:
http://download.microsoft.com/download/excel2000/sample/2000/w9x2k/en-us/ChartGIF.exe


adding
Response.AddHeader "content-length", objFile.Size
enables the browser to show a progress bar to the user... "downloading xyz.csv. 3.4MB from 5.8MB"
Cheers!
Michel
MCAD, MCSA, MCDBA
0
 
LVL 20

Expert Comment

by:Michel Sakr
ID: 9360797
So humble Moderator.. any news.. your feedback should be @ the speed of lightening :o)

Cheers!
Michel
MCAD, MCSA, MCDBA
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:madeline448
ID: 9360817
Silvers5,

still working on your codes...hope that i was doing it right, my mind is not in sync...**bump bump bump
0
 
LVL 1

Author Comment

by:madeline448
ID: 9361135
Silvers5,
question...is the strFileName a mappath of virtual path?
0
 
LVL 20

Expert Comment

by:Michel Sakr
ID: 9361196
>strFileName a mappath of virtual path?
whatever you like.. it can be both
it can be
Response.BinaryWrite objBinaryFile.GetFileBytes(CStr(server.mappath(strFileName)))
to get the physical path..
0
 
LVL 1

Author Comment

by:madeline448
ID: 9367669
Hi,

Everythings working fine now. Thanks Silvers.

BTW, I found this link somewhere, could be useful too http://www.xefteri.com/articles/may082002/default.aspx
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question