By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,830 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,830 IT Pros & Developers. It's quick & easy.

auto download csv file

P: n/a
How can I force a download of a csv file by user clicking on hyperlink.
Don
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
try :

<a href="myCSVFile.csv">click here</a>

If it opens in the browser then the user needs to amend their settings.

see http://www.greggriffiths.org/webdev/both/excel/ for some other
approaches.

Don Grover wrote:
How can I force a download of a csv file by user clicking on hyperlink.
Don


Jul 19 '05 #2

P: n/a
Thanks Greg.
Had a look but what I am after, I have a complex qry that financial users
select data from a web page by submitting a form.
I am calling an asp page that gets the data format as they require and I
have it a STRING in csv format.
The above is working correctly.

What I want to do is automatically bring up a save as box to prompt them to
save it, I really dont want to save as file first unless I have too.

Anyone have any ideas.
Don

"Greg Griffiths" <gr***@surfaid.org> wrote in message
news:3F***************@surfaid.org...
try :

<a href="myCSVFile.csv">click here</a>

If it opens in the browser then the user needs to amend their settings.

see http://www.greggriffiths.org/webdev/both/excel/ for some other
approaches.

Don Grover wrote:
How can I force a download of a csv file by user clicking on hyperlink.
Don

Jul 19 '05 #3

P: n/a
Look at ADODB.Stream
http://support.microsoft.com/default...NoWebContent=1

You can load the object with the CSV and as long as the HTTP headers are set
correctly thenthe binary output (as Response.Write) will prompt the Save AS
dialog.

<%
'Set the content type to the specific type that you are sending.
Response.ContentType = "text/csv"

Const adTypeText = 2

'Create Stream object
Dim pobjStream
Set pobjStream = Server.CreateObject("ADODB.Stream")

'Specify stream type - we want To save text/string data.
pobjStream.Type = adTypeText

'Open the stream And write binary data To the object
pobjStream.Open
pobjStream.WriteText [YourGeneratedCSVText]

Response.BinaryWrite objStream.Read

pobjStream.Close
Set pobjStream = Nothing
%>
**** That might be Response.Write as opposed to BinaryWrite - not sure at
the moment.

Chris.

"Don Grover" <sp******@assoft.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks Greg.
Had a look but what I am after, I have a complex qry that financial users
select data from a web page by submitting a form.
I am calling an asp page that gets the data format as they require and I
have it a STRING in csv format.
The above is working correctly.

What I want to do is automatically bring up a save as box to prompt them to
save it, I really dont want to save as file first unless I have too.

Anyone have any ideas.
Don

"Greg Griffiths" <gr***@surfaid.org> wrote in message
news:3F***************@surfaid.org...
try :

<a href="myCSVFile.csv">click here</a>

If it opens in the browser then the user needs to amend their settings.

see http://www.greggriffiths.org/webdev/both/excel/ for some other
approaches.

Don Grover wrote:
How can I force a download of a csv file by user clicking on hyperlink.
Don

Jul 19 '05 #4

P: n/a
Thanks Chris
I can now get it to show a saved as box but it keeps putting in the actual
asp page as the file saveas file name.
How can I preload a file name.
'****************************
Heres my Code

'Set the content type to the specific type that you are sending.
Response.ContentType = "text/csv"

Const adTypeBinary = 1
Dim strFilePath

strFilePath = "c:\cokeshopScripts\exportdata.csv" 'This is the path to the
file on disk.

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

Response.Binarywrite objStream.Read

objStream.Close
Set objStream = Nothing

'******************************************

"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Look at ADODB.Stream
http://support.microsoft.com/default...NoWebContent=1
You can load the object with the CSV and as long as the HTTP headers are set correctly thenthe binary output (as Response.Write) will prompt the Save AS dialog.

<%
'Set the content type to the specific type that you are sending.
Response.ContentType = "text/csv"

Const adTypeText = 2

'Create Stream object
Dim pobjStream
Set pobjStream = Server.CreateObject("ADODB.Stream")

'Specify stream type - we want To save text/string data.
pobjStream.Type = adTypeText

'Open the stream And write binary data To the object
pobjStream.Open
pobjStream.WriteText [YourGeneratedCSVText]

Response.BinaryWrite objStream.Read

pobjStream.Close
Set pobjStream = Nothing
%>
**** That might be Response.Write as opposed to BinaryWrite - not sure at
the moment.

Chris.

"Don Grover" <sp******@assoft.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks Greg.
Had a look but what I am after, I have a complex qry that financial users
select data from a web page by submitting a form.
I am calling an asp page that gets the data format as they require and I
have it a STRING in csv format.
The above is working correctly.

What I want to do is automatically bring up a save as box to prompt them to save it, I really dont want to save as file first unless I have too.

Anyone have any ideas.
Don

"Greg Griffiths" <gr***@surfaid.org> wrote in message
news:3F***************@surfaid.org...
try :

<a href="myCSVFile.csv">click here</a>

If it opens in the browser then the user needs to amend their settings.

see http://www.greggriffiths.org/webdev/both/excel/ for some other
approaches.

Don Grover wrote:
How can I force a download of a csv file by user clicking on hyperlink. Don


Jul 19 '05 #5

P: n/a
Response.addHeader("content-disposition",
"attachment;filename=somefile.csv")

Chris.

"Don Grover" <sp******@assoft.com.au> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks Chris
I can now get it to show a saved as box but it keeps putting in the actual
asp page as the file saveas file name.
How can I preload a file name.
'****************************
Heres my Code

'Set the content type to the specific type that you are sending.
Response.ContentType = "text/csv"

Const adTypeBinary = 1
Dim strFilePath

strFilePath = "c:\cokeshopScripts\exportdata.csv" 'This is the path to the
file on disk.

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

Response.Binarywrite objStream.Read

objStream.Close
Set objStream = Nothing

'******************************************

"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Look at ADODB.Stream
http://support.microsoft.com/default...NoWebContent=1
You can load the object with the CSV and as long as the HTTP headers are set correctly thenthe binary output (as Response.Write) will prompt the Save AS dialog.

<%
'Set the content type to the specific type that you are sending.
Response.ContentType = "text/csv"

Const adTypeText = 2

'Create Stream object
Dim pobjStream
Set pobjStream = Server.CreateObject("ADODB.Stream")

'Specify stream type - we want To save text/string data.
pobjStream.Type = adTypeText

'Open the stream And write binary data To the object
pobjStream.Open
pobjStream.WriteText [YourGeneratedCSVText]

Response.BinaryWrite objStream.Read

pobjStream.Close
Set pobjStream = Nothing
%>
**** That might be Response.Write as opposed to BinaryWrite - not sure at
the moment.

Chris.

"Don Grover" <sp******@assoft.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks Greg.
Had a look but what I am after, I have a complex qry that financial users
select data from a web page by submitting a form.
I am calling an asp page that gets the data format as they require and I
have it a STRING in csv format.
The above is working correctly.

What I want to do is automatically bring up a save as box to prompt them to save it, I really dont want to save as file first unless I have too.

Anyone have any ideas.
Don

"Greg Griffiths" <gr***@surfaid.org> wrote in message
news:3F***************@surfaid.org...
try :

<a href="myCSVFile.csv">click here</a>

If it opens in the browser then the user needs to amend their settings.

see http://www.greggriffiths.org/webdev/both/excel/ for some other
approaches.

Don Grover wrote:
How can I force a download of a csv file by user clicking on hyperlink. Don



Jul 19 '05 #6

P: n/a
Thanks chris, works like a dream.

"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl...
Response.addHeader("content-disposition",
"attachment;filename=somefile.csv")

Chris.

"Don Grover" <sp******@assoft.com.au> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks Chris
I can now get it to show a saved as box but it keeps putting in the actual
asp page as the file saveas file name.
How can I preload a file name.
'****************************
Heres my Code

'Set the content type to the specific type that you are sending.
Response.ContentType = "text/csv"

Const adTypeBinary = 1
Dim strFilePath

strFilePath = "c:\cokeshopScripts\exportdata.csv" 'This is the path to the
file on disk.

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

Response.Binarywrite objStream.Read

objStream.Close
Set objStream = Nothing

'******************************************

"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Look at ADODB.Stream

http://support.microsoft.com/default...NoWebContent=1

You can load the object with the CSV and as long as the HTTP headers are

set
correctly thenthe binary output (as Response.Write) will prompt the Save

AS
dialog.

<%
'Set the content type to the specific type that you are sending.
Response.ContentType = "text/csv"

Const adTypeText = 2

'Create Stream object
Dim pobjStream
Set pobjStream = Server.CreateObject("ADODB.Stream")

'Specify stream type - we want To save text/string data.
pobjStream.Type = adTypeText

'Open the stream And write binary data To the object
pobjStream.Open
pobjStream.WriteText [YourGeneratedCSVText]

Response.BinaryWrite objStream.Read

pobjStream.Close
Set pobjStream = Nothing
%>
**** That might be Response.Write as opposed to BinaryWrite - not sure at
the moment.

Chris.

"Don Grover" <sp******@assoft.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks Greg.
Had a look but what I am after, I have a complex qry that financial users select data from a web page by submitting a form.
I am calling an asp page that gets the data format as they require and I
have it a STRING in csv format.
The above is working correctly.

What I want to do is automatically bring up a save as box to prompt them

to
save it, I really dont want to save as file first unless I have too.

Anyone have any ideas.
Don

"Greg Griffiths" <gr***@surfaid.org> wrote in message
news:3F***************@surfaid.org...
try :

<a href="myCSVFile.csv">click here</a>

If it opens in the browser then the user needs to amend their settings.
see http://www.greggriffiths.org/webdev/both/excel/ for some other
approaches.

Don Grover wrote:

> How can I force a download of a csv file by user clicking on

hyperlink. > Don



Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.