IIS ASP - Slick way to generate a CSV for user download?

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > May 2005 > Slick way to generate a CSV for user download?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Slick way to generate a CSV for user download?
MyndPhlyp

2005-05-20, 6:03 pm

I've been trying to Google this but have been getting far too many hits to
be of use. Is there a slick way to generate a CSV or other Excel-friendly
format and push it to the client? I'm using VBScript (and HTML and other
typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
the right direction is all I really need here.


Ray Costanzo [MVP]

2005-05-20, 6:03 pm

What's your data source?

Ray at work

"MyndPhlyp" <nobody@homeright.now> wrote in message
news:%23$zD9WXXFHA.712@TK2MSFTNGP14.phx.gbl...
> I've been trying to Google this but have been getting far too many hits to
> be of use. Is there a slick way to generate a CSV or other Excel-friendly
> format and push it to the client? I'm using VBScript (and HTML and other
> typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
> the right direction is all I really need here.
>
>



Mark Schupp

2005-05-20, 6:03 pm

Response.ContentType = "text/comma-separated-values"
Response.AddHeader "Content-Disposition","attachment; filename=extract.csv"

For i = 1 to 10

Next
Response.Write CSVString( "row" & CStr(i)) & "," & CSVString("column 2")
& vbCrLf
Response.end

Function CSVString( ByVal strIn )
If IsNull( strIn ) Then strIn = ""
CSVString = """" & Replace(strIn, """", "'") & """"
CSVString = Replace(CSVString, vbCrLf, "<cr>")
End Function

--
--Mark Schupp


"MyndPhlyp" <nobody@homeright.now> wrote in message
news:%23$zD9WXXFHA.712@TK2MSFTNGP14.phx.gbl...
> I've been trying to Google this but have been getting far too many hits to
> be of use. Is there a slick way to generate a CSV or other Excel-friendly
> format and push it to the client? I'm using VBScript (and HTML and other
> typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
> the right direction is all I really need here.
>
>



Kyle Peterson

2005-05-20, 6:03 pm

just query the database... write the text file string line by line and
create the file however you wan it with the filesystem object

its pretty easy really


"MyndPhlyp" <nobody@homeright.now> wrote in message
news:%23$zD9WXXFHA.712@TK2MSFTNGP14.phx.gbl...
> I've been trying to Google this but have been getting far too many hits to
> be of use. Is there a slick way to generate a CSV or other Excel-friendly
> format and push it to the client? I'm using VBScript (and HTML and other
> typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
> the right direction is all I really need here.
>
>



MyndPhlyp

2005-05-20, 6:03 pm

SQL Server 2K via ADODB.Recordset


"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:ev9uzhXXFHA.616@TK2MSFTNGP12.phx.gbl...
> What's your data source?
>
> Ray at work
>
> "MyndPhlyp" <nobody@homeright.now> wrote in message
> news:%23$zD9WXXFHA.712@TK2MSFTNGP14.phx.gbl...
to[vbcol=seagreen]
Excel-friendly[vbcol=seagreen]
in[vbcol=seagreen]
>
>



MyndPhlyp

2005-05-20, 6:03 pm


"Mark Schupp" <notvalid@email.net> wrote in message
news:edmGS8XXFHA.3164@TK2MSFTNGP12.phx.gbl...
> Response.ContentType = "text/comma-separated-values"
> Response.AddHeader "Content-Disposition","attachment;

filename=extract.csv"
>
> For i = 1 to 10
>
> Next
> Response.Write CSVString( "row" & CStr(i)) & "," & CSVString("column

2")
> & vbCrLf
> Response.end
>
> Function CSVString( ByVal strIn )
> If IsNull( strIn ) Then strIn = ""
> CSVString = """" & Replace(strIn, """", "'") & """"
> CSVString = Replace(CSVString, vbCrLf, "<cr>")
> End Function


Yeah, that's kind of what I was looking for. Short, sweet and simple. Thanx
for ruining my weekend with yet another thing to play around with. <G> (It's
s'posed to rain anyway.)


Hal Rosser

2005-05-21, 8:47 pm


"MyndPhlyp" <nobody@homeright.now> wrote in message
news:%23$zD9WXXFHA.712@TK2MSFTNGP14.phx.gbl...
> I've been trying to Google this but have been getting far too many hits to
> be of use. Is there a slick way to generate a CSV or other Excel-friendly
> format and push it to the client? I'm using VBScript (and HTML and other
> typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
> the right direction is all I really need here.
>


Create the csv file on the server
provide a link to that file on the asp page


MyndPhlyp

2005-05-21, 8:47 pm


"Hal Rosser" <hmrosser@bellsouth.net> wrote in message
news:diQje.5145$6k7.1754@bignews4.bellsouth.net...
>
> "MyndPhlyp" <nobody@homeright.now> wrote in message
> news:%23$zD9WXXFHA.712@TK2MSFTNGP14.phx.gbl...
to[vbcol=seagreen]
Excel-friendly[vbcol=seagreen]
in[vbcol=seagreen]
>
> Create the csv file on the server
> provide a link to that file on the asp page


Thanks Hal, but the Response.Write et al solution earlier in this thread
appears to be the better alternative to files. The CSV, although I didn't
mention it, is the contents of a tabular report currently being viewed by
the user so it has to be generated on demand. As you might guess, this is
for an internal web. Doint it this way allows me to skip the creation to
disk and instead just push the stuff to the user ... on demand, of course.


Roland Hall

2005-05-22, 7:47 am

"Mark Schupp" wrote in message news:edmGS8XXFHA.3164@TK2MSFTNGP12.phx.gbl...
: Response.ContentType = "text/comma-separated-values"
: Response.AddHeader "Content-Disposition","attachment;
filename=extract.csv"
:
: For i = 1 to 10
:
: Next
: Response.Write CSVString( "row" & CStr(i)) & "," & CSVString("column
2")
: & vbCrLf
: Response.end
:
: Function CSVString( ByVal strIn )
: If IsNull( strIn ) Then strIn = ""
: CSVString = """" & Replace(strIn, """", "'") & """"
: CSVString = Replace(CSVString, vbCrLf, "<cr>")
: End Function

In this example, shouldn't the response.write goes inside the for...next
loop?
And, how do you keep from getting the Action cancelled page?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


MyndPhlyp

2005-05-22, 5:49 pm


"Roland Hall" <nobody@nowhere> wrote in message
news:%23Dj58oqXFHA.3572@TK2MSFTNGP12.phx.gbl...
> "Mark Schupp" wrote in message

news:edmGS8XXFHA.3164@TK2MSFTNGP12.phx.gbl...
> : Response.ContentType = "text/comma-separated-values"
> : Response.AddHeader "Content-Disposition","attachment;
> filename=extract.csv"
> :
> : For i = 1 to 10
> :
> : Next
> : Response.Write CSVString( "row" & CStr(i)) & "," & CSVString("column
> 2")
> : & vbCrLf
> : Response.end
> :
> : Function CSVString( ByVal strIn )
> : If IsNull( strIn ) Then strIn = ""
> : CSVString = """" & Replace(strIn, """", "'") & """"
> : CSVString = Replace(CSVString, vbCrLf, "<cr>")
> : End Function
>
> In this example, shouldn't the response.write goes inside the for...next
> loop?
> And, how do you keep from getting the Action cancelled page?


It is an oversimplified example probably modified in haste. I think just
about everybody has been guilty of that at least once in their life. Yes,
the Response.Write should be between the For and Next. My query was
interpreted correctly though - how to push a file to a browser. The key bits
are the Response.ContentType and Response.AddHeader methods (to which I add
Response.Clear at the beginning and Response.Flush just before the
Response.End). What happens between the Response.AddHeader and the
Response.Flush, Response.End is really of no consequence.


Roland Hall

2005-05-22, 5:49 pm

"MyndPhlyp" wrote in message news:uc9686uXFHA.3840@tk2msftngp13.phx.gbl...
:
: "Roland Hall" <nobody@nowhere> wrote in message
: news:%23Dj58oqXFHA.3572@TK2MSFTNGP12.phx.gbl...
: > "Mark Schupp" wrote in message
: news:edmGS8XXFHA.3164@TK2MSFTNGP12.phx.gbl...
: > : Response.ContentType = "text/comma-separated-values"
: > : Response.AddHeader "Content-Disposition","attachment;
: > filename=extract.csv"
: > :
: > : For i = 1 to 10
: > :
: > : Next
: > : Response.Write CSVString( "row" & CStr(i)) & "," &
CSVString("column
: > 2")
: > : & vbCrLf
: > : Response.end
: > :
: > : Function CSVString( ByVal strIn )
: > : If IsNull( strIn ) Then strIn = ""
: > : CSVString = """" & Replace(strIn, """", "'") & """"
: > : CSVString = Replace(CSVString, vbCrLf, "<cr>")
: > : End Function
: >
: > In this example, shouldn't the response.write goes inside the for...next
: > loop?
: > And, how do you keep from getting the Action cancelled page?
:
: It is an oversimplified example probably modified in haste. I think just
: about everybody has been guilty of that at least once in their life. Yes,
: the Response.Write should be between the For and Next. My query was
: interpreted correctly though - how to push a file to a browser. The key
bits
: are the Response.ContentType and Response.AddHeader methods (to which I
add
: Response.Clear at the beginning and Response.Flush just before the
: Response.End). What happens between the Response.AddHeader and the
: Response.Flush, Response.End is really of no consequence.

It is to me. I was asking for knowledge, not to challenge. I wasn't aware
I could send content as a file without first having a file.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Dave Anderson

2005-05-22, 5:49 pm

MyndPhlyp wrote:
> I've been trying to Google this but have been getting far too many
> hits to be of use. Is there a slick way to generate a CSV or other
> Excel-friendly format and push it to the client? I'm using VBScript
> (and HTML and other typical stuff of course) on the ASP pages (no
> .NET stuff). Just a shove in the right direction is all I really need
> here.


Response.AddHeader("Content-Disposition","attachment; filename=myfile.csv")
Response.ContentType = "text/csv"
Response.Write(oRS.GetString(2,,","))

http://msdn.microsoft.com/library/e...bf79a0994da.asp
http://msdn.microsoft.com/library/e...69dfcfd053c.asp
http://msdn.microsoft.com/library/e...getstringmethod(recordset)ado.asp


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


MyndPhlyp

2005-05-22, 5:49 pm


"Roland Hall" <nobody@nowhere> wrote in message
news:eGFjUcwXFHA.2796@TK2MSFTNGP09.phx.gbl...
>
> It is to me. I was asking for knowledge, not to challenge. I wasn't

aware
> I could send content as a file without first having a file.


I too was unaware ... 'till now. It has since been permanently recorded in
that feeble cabinet I call a brain (only to eventually get lost in the dust
of time).


MyndPhlyp

2005-05-22, 5:49 pm


"Dave Anderson" <GTSPXOESSGOQ@spammotel.com> wrote in message
news:1191op78tu3qlf3@corp.supernews.com...
>
>

http://msdn.microsoft.com/library/e...bf79a0994da.asp
>

http://msdn.microsoft.com/library/e...69dfcfd053c.asp
>

http://msdn.microsoft.com/library/e...getstringmethod(recordset)ado.asp


Cool. I wasn't aware of the Recordset.GetString method. Thanx.

BTW - I used to know a Dave Anderson hundreds of years ago in New England.
We called him "Uncle Dave" 'cus he was an only child (and therefore would
never be an uncle). On a longshot, would that happen to be you?


Mark Schupp

2005-05-23, 5:59 pm

> : It is an oversimplified example probably modified in haste. I think just
> : about everybody has been guilty of that at least once in their life.

Yes,
> : the Response.Write should be between the For and Next. My query was
> : interpreted correctly though - how to push a file to a browser. The key


It was between the for and next when I tested the code. It pasted into the
message very strangely. I did notice and thought I fixed it (my whole life
has been weird lately).

IIRC the "action canceled" is a weird bug (or maybe a "feature") in IE.
Having to do with whether the page is called using GET or POST. Try using
GET.

--
Mark Schupp



"Roland Hall" <nobody@nowhere> wrote in message
news:eGFjUcwXFHA.2796@TK2MSFTNGP09.phx.gbl...
> "MyndPhlyp" wrote in message news:uc9686uXFHA.3840@tk2msftngp13.phx.gbl...
> :
> : "Roland Hall" <nobody@nowhere> wrote in message
> : news:%23Dj58oqXFHA.3572@TK2MSFTNGP12.phx.gbl...
> : > "Mark Schupp" wrote in message
> : news:edmGS8XXFHA.3164@TK2MSFTNGP12.phx.gbl...
> : > : Response.ContentType = "text/comma-separated-values"
> : > : Response.AddHeader "Content-Disposition","attachment;
> : > filename=extract.csv"
> : > :
> : > : For i = 1 to 10
> : > :
> : > : Next
> : > : Response.Write CSVString( "row" & CStr(i)) & "," &
> CSVString("column
> : > 2")
> : > : & vbCrLf
> : > : Response.end
> : > :
> : > : Function CSVString( ByVal strIn )
> : > : If IsNull( strIn ) Then strIn = ""
> : > : CSVString = """" & Replace(strIn, """", "'") & """"
> : > : CSVString = Replace(CSVString, vbCrLf, "<cr>")
> : > : End Function
> : >
> : > In this example, shouldn't the response.write goes inside the

for...next
> : > loop?
> : > And, how do you keep from getting the Action cancelled page?
> :
> : It is an oversimplified example probably modified in haste. I think just
> : about everybody has been guilty of that at least once in their life.

Yes,
> : the Response.Write should be between the For and Next. My query was
> : interpreted correctly though - how to push a file to a browser. The key
> bits
> : are the Response.ContentType and Response.AddHeader methods (to which I
> add
> : Response.Clear at the beginning and Response.Flush just before the
> : Response.End). What happens between the Response.AddHeader and the
> : Response.Flush, Response.End is really of no consequence.
>
> It is to me. I was asking for knowledge, not to challenge. I wasn't

aware
> I could send content as a file without first having a file.
>
> --
> Roland Hall
> /* This information is distributed in the hope that it will be useful, but
> without any warranty; without even the implied warranty of merchantability
> or fitness for a particular purpose. */
> technet Script Center - http://www.microsoft.com/technet/scriptcenter/
> WSH 5.6 Documentation -

http://msdn.microsoft.com/downloads/list/webdev.asp
> MSDN Library - http://msdn.microsoft.com/library/default.asp
>
>



Roland Hall

2005-05-23, 5:59 pm

"MyndPhlyp" wrote in message news:e4x6WuwXFHA.1148@tk2msftngp13.phx.gbl...
:
: "Roland Hall" <nobody@nowhere> wrote in message
: news:eGFjUcwXFHA.2796@TK2MSFTNGP09.phx.gbl...
: >
: > It is to me. I was asking for knowledge, not to challenge. I wasn't
: aware
: > I could send content as a file without first having a file.
:
: I too was unaware ... 'till now. It has since been permanently recorded in
: that feeble cabinet I call a brain (only to eventually get lost in the
dust
: of time).

Lucky brain owner... heading to Oz.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Roland Hall

2005-05-23, 5:59 pm

"Mark Schupp" wrote in message news:uO8PeM7XFHA.1148@tk2msftngp13.phx.gbl...
:> : It is an oversimplified example probably modified in haste. I think
just
: > : about everybody has been guilty of that at least once in their life.
: Yes,
: > : the Response.Write should be between the For and Next. My query was
: > : interpreted correctly though - how to push a file to a browser. The
key
:
: It was between the for and next when I tested the code. It pasted into the
: message very strangely. I did notice and thought I fixed it (my whole life
: has been weird lately).

That is weird. You must have a special browser. Could probably call it Ed.
(O;=

: IIRC the "action canceled" is a weird bug (or maybe a "feature") in IE.
: Having to do with whether the page is called using GET or POST. Try using
: GET.

I'll try that. I would assume (cough) this means this is not an option to
send an attachment by server-side email, or is it, meaning gathering data
and sending an attachment by CDOSYS without first saving it as a file?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


MyndPhlyp

2005-05-24, 8:25 am


"Roland Hall" <nobody@nowhere> wrote in message
news:%23HcDfr9XFHA.2128@TK2MSFTNGP15.phx.gbl...
> "MyndPhlyp" wrote in message news:e4x6WuwXFHA.1148@tk2msftngp13.phx.gbl...
> :
> : I too was unaware ... 'till now. It has since been permanently recorded

in
> : that feeble cabinet I call a brain (only to eventually get lost in the
> dust
> : of time).
>
> Lucky brain owner... heading to Oz.


I am not too sure about the "lucky" part. There appears to be significant
irreversible damage and I strongly suspect it is a hand-me-down from a
research project at a remote asylum. Whether or not it is even accurate to
call it a "brain" is left up to the medical examiner that will perform the
eventual autopsy hopefully many years from now. But thanks for the optimism.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com