auto download csv file

D

Don Grover

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
 
C

Chris Barber

Look at ADODB.Stream
http://support.microsoft.com/defaul...port/kb/articles/q276/4/88.asp&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.

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
 
D

Don Grover

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 said:
Look at ADODB.Stream
http://support.microsoft.com/defaul...port/kb/articles/q276/4/88.asp&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.

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 said:
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.
 
C

Chris Barber

Response.addHeader("content-disposition",
"attachment;filename=somefile.csv")

Chris.

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 said:
Look at ADODB.Stream
http://support.microsoft.com/defaul...port/kb/articles/q276/4/88.asp&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.

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 said:
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.
 
D

Don Grover

Thanks chris, works like a dream.

Chris Barber said:
Response.addHeader("content-disposition",
"attachment;filename=somefile.csv")

Chris.

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 said:
Look at ADODB.Stream
http://support.microsoft.com/defaul...port/kb/articles/q276/4/88.asp&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.

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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,816
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top