Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: tab-delimited file


Message #1 by "Carlos Lamar" <lamar@s...> on Fri, 5 Jul 2002 13:30:40 -0700
Hello,

I am using the following code to generate a tab-delimited file which
will open in Excel from my ASP page. I am getting a 0-byte file, even
though there is data in the recordset.  Any ideas on what may be the
problem will be greatly appreciated...

Thanks!

----
<%@ Language=3DVBScript %>
<%	Response.Expires =3D 0 %>

<html>

<body>

<!-- #include file=3D"adovbs.inc" -->
<%

Dim DataConn, RS, rSearch, SQL, mid
rSearch =3D Request.Form("tn")

nRandom =3D Int((1000000 - 1 + 1) * Rnd + 1000000)
fileExcel =3D "t" & CStr(nRandom) & ".xls"

filename =3D Server.Mappath("/") & fileExcel

Set fs =3D Server.CreateObject("Scripting.FileSystemObject")
Set MyFile =3D fs.CreateTextFile(filename, True)

Set DataConn =3D Server.CreateObject("ADODB.Connection")
Set RS =3D Server.CreateObject("ADODB.Recordset")
DataConn.Open "DBQ=3D" & Server.Mappath("./fpdb/mytable.mdb") &
";Driver=3D{Microsoft Access Driver (*.mdb)};"

SQL =3D " select * " _
    & " from mytable " _
    & " where tray_num =3D'" & rSearch & "' " _
    & " order by item, ID "

RS.Open SQL, DataConn
%>

<head>
<meta http-equiv=3D"Content-Language" content=3D"en-us">
<meta name=3D"GENERATOR" content=3D"Microsoft FrontPage 5.0">
<meta name=3D"ProgId" content=3D"FrontPage.Editor.Document">
<meta http-equiv=3D"Content-Type" content=3D"text/html;
charset=3Dwindows-1252">
<title>THIS IS A TEST</title>
<meta name=3D"Microsoft Border" content=3D"b, default">
</head>

<div align=3D"center">
  <center>
  <table border=3D"1" cellpadding=3D"0" cellspacing=3D"0"
style=3D"border-collapse: collapse" bordercolor=3D"#111111" 
width=3D"90%">
<% While Not RS.eof
	  strLine=3D""
      for each x in RS.Fields
    	  strLine=3D strLine & x.value & chr(9)
      next
      MyFile.writeline strLine
      RS.MoveNext
   Wend
%>
  </table>
  </center>
</div>
<%
' Tidy up
Set RS =3D nothing
DataConn.Close
Set DataConn =3D nothing

MyFile.Close
Set MyFile=3DNothing
Set fs=3DNothing

'Show a link to the Excel File.
link=3D"<A HREF=3D" & fileExcel & ">Open Excel</a>"
       Response.write link
%> </body>
</html>

----

____________________________________________________
Carlos L. LaMar
Executive VP, IS & Management Development
snyder/newell, inc.
> *:   xxx.xxx.xxxx
> *:   xxx.xxx.xxxx   (FAX)
> *:  clamar@s...
> u http://www.snyder-newell.com/
>
>
>
Message #2 by "Larry Woods" <larry@l...> on Fri, 5 Jul 2002 16:57:25 -0700
Looks good to me...at a quick pass.  I do the same thing myself.
Have you verified that you have any records to write out?  Also,
I assume that your SELECT field 'tray_num' is defined as a text
file in your database since that is the way that you have it
defined in your SELECT.  Since you have your file build defined
in the HTML page, why don't you dump the records back to the
browser so that you can see what you SHOULD be getting.  For that
matter, dump the records that you are writing to the file.

Larry Woods


> -----Original Message-----
> From: Carlos Lamar [mailto:lamar@s...]
> Sent: Friday, July 05, 2002 1:31 PM
> To: ASP Web HowTo
> Subject: [asp_web_howto] tab-delimited file
>
>
> Hello,
>
> I am using the following code to generate a
> tab-delimited file which
> will open in Excel from my ASP page. I am getting a
> 0-byte file, even
> though there is data in the recordset.  Any ideas on
> what may be the
> problem will be greatly appreciated...
>
> Thanks!
>
> ----
> <%@ Language=VBScript %>
> <%	Response.Expires = 0 %>
>
> <html>
>
> <body>
>
> <!-- #include file="adovbs.inc" -->
> <%
>
> Dim DataConn, RS, rSearch, SQL, mid
> rSearch = Request.Form("tn")
>
> nRandom = Int((1000000 - 1 + 1) * Rnd + 1000000)
> fileExcel = "t" & CStr(nRandom) & ".xls"
>
> filename = Server.Mappath("/") & fileExcel
>
> Set fs = Server.CreateObject("Scripting.FileSystemObject")
> Set MyFile = fs.CreateTextFile(filename, True)
>
> Set DataConn = Server.CreateObject("ADODB.Connection")
> Set RS = Server.CreateObject("ADODB.Recordset")
> DataConn.Open "DBQ=" & Server.Mappath("./fpdb/mytable.mdb") &
> ";Driver={Microsoft Access Driver (*.mdb)};"
>
> SQL = " select * " _
>     & " from mytable " _
>     & " where tray_num ='" & rSearch & "' " _
>     & " order by item, ID "
>
> RS.Open SQL, DataConn
> %>
>
> <head>
> <meta http-equiv="Content-Language" content="en-us">
> <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
> <meta name="ProgId" content="FrontPage.Editor.Document">
> <meta http-equiv="Content-Type" content="text/html;
> charset=windows-1252">
> <title>THIS IS A TEST</title>
> <meta name="Microsoft Border" content="b, default">
> </head>
>
> <div align="center">
>   <center>
>   <table border="1" cellpadding="0" cellspacing="0"
> style="border-collapse: collapse"
> bordercolor="#111111" width="90%">
> <% While Not RS.eof
> 	  strLine=""
>       for each x in RS.Fields
>     	  strLine= strLine & x.value & chr(9)
>       next
>       MyFile.writeline strLine
>       RS.MoveNext
>    Wend
> %>
>   </table>
>   </center>
> </div>
> <%
> ' Tidy up
> Set RS = nothing
> DataConn.Close
> Set DataConn = nothing
>
> MyFile.Close
> Set MyFile=Nothing
> Set fs=Nothing
>
> 'Show a link to the Excel File.
> link="<A HREF=" & fileExcel & ">Open Excel</a>"
>        Response.write link
> %> </body>
> </html>
>
> ----
>
> ____________________________________________________
> Carlos L. LaMar
> Executive VP, IS & Management Development
> snyder/newell, inc.
> > *:   xxx.xxx.xxxx
> > *:   xxx.xxx.xxxx   (FAX)
> > *:  clamar@s...
> > u http://www.snyder-newell.com/
> >
> >
> >
>
>
> ---
>
> Improve your web design skills with these new books
> from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=n
osim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/thepr
ogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/thepr
ogramme
r-20

Message #3 by "Carlos Lamar" <lamar@s...> on Mon, 8 Jul 2002 09:07:23 -0700
Thanks, Larry,

You were correct...  there were no records to write out...  I corrected
it and it works fine now. 
Regards,
---Carlos

____________________________________________________
Carlos L. LaMar
Executive VP, IS & Management Development
snyder/newell, inc.
> *:   xxx.xxx.xxxx
> *:   xxx.xxx.xxxx   (FAX)
> *:  clamar@s...
> u http://www.snyder-newell.com/
>
>
>
> ----------
> From: 	Larry Woods[SMTP:larry@l...]
> Reply To: 	ASP Web HowTo
> Sent: 	Friday, July 05, 2002 4:57 PM
> To: 	ASP Web HowTo
> Subject: 	[asp_web_howto] RE: tab-delimited file
>
> Looks good to me...at a quick pass.  I do the same thing myself.
> Have you verified that you have any records to write out?  Also,
> I assume that your SELECT field 'tray_num' is defined as a text
> file in your database since that is the way that you have it
> defined in your SELECT.  Since you have your file build defined
> in the HTML page, why don't you dump the records back to the
> browser so that you can see what you SHOULD be getting.  For that
> matter, dump the records that you are writing to the file.
>
> Larry Woods
>
>
> > -----Original Message-----
> > From: Carlos Lamar [mailto:lamar@s...]
> > Sent: Friday, July 05, 2002 1:31 PM
> > To: ASP Web HowTo
> > Subject: [asp_web_howto] tab-delimited file
> >
> >
> > Hello,
> >
> > I am using the following code to generate a
> > tab-delimited file which
> > will open in Excel from my ASP page. I am getting a
> > 0-byte file, even
> > though there is data in the recordset.  Any ideas on
> > what may be the
> > problem will be greatly appreciated...
> >
> > Thanks!
> >
> > ----
> > <%@ Language=3DVBScript %>
> > <%	Response.Expires =3D 0 %>
> >
> > <html>
> >
> > <body>
> >
> > <!-- #include file=3D"adovbs.inc" -->
> > <%
> >
> > Dim DataConn, RS, rSearch, SQL, mid
> > rSearch =3D Request.Form("tn")
> >
> > nRandom =3D Int((1000000 - 1 + 1) * Rnd + 1000000)
> > fileExcel =3D "t" & CStr(nRandom) & ".xls"
> >
> > filename =3D Server.Mappath("/") & fileExcel
> >
> > Set fs =3D Server.CreateObject("Scripting.FileSystemObject")
> > Set MyFile =3D fs.CreateTextFile(filename, True)
> >
> > Set DataConn =3D Server.CreateObject("ADODB.Connection")
> > Set RS =3D Server.CreateObject("ADODB.Recordset")
> > DataConn.Open "DBQ=3D" & Server.Mappath("./fpdb/mytable.mdb") &
> > ";Driver=3D{Microsoft Access Driver (*.mdb)};"
> >
> > SQL =3D " select * " _
> >     & " from mytable " _
> >     & " where tray_num =3D'" & rSearch & "' " _
> >     & " order by item, ID "
> >
> > RS.Open SQL, DataConn
> > %>
> >
> > <head>
> > <meta http-equiv=3D"Content-Language" content=3D"en-us">
> > <meta name=3D"GENERATOR" content=3D"Microsoft FrontPage 5.0">
> > <meta name=3D"ProgId" content=3D"FrontPage.Editor.Document">
> > <meta http-equiv=3D"Content-Type" content=3D"text/html;
> > charset=3Dwindows-1252">
> > <title>THIS IS A TEST</title>
> > <meta name=3D"Microsoft Border" content=3D"b, default">
> > </head>
> >
> > <div align=3D"center">
> >   <center>
> >   <table border=3D"1" cellpadding=3D"0" cellspacing=3D"0"
> > style=3D"border-collapse: collapse"
> > bordercolor=3D"#111111" width=3D"90%">
> > <% While Not RS.eof
> > 	  strLine=3D""
> >       for each x in RS.Fields
> >     	  strLine=3D strLine & x.value & chr(9)
> >       next
> >       MyFile.writeline strLine
> >       RS.MoveNext
> >    Wend
> > %>
> >   </table>
> >   </center>
> > </div>
> > <%
> > ' Tidy up
> > Set RS =3D nothing
> > DataConn.Close
> > Set DataConn =3D nothing
> >
> > MyFile.Close
> > Set MyFile=3DNothing
> > Set fs=3DNothing
> >
> > 'Show a link to the Excel File.
> > link=3D"<A HREF=3D" & fileExcel & ">Open Excel</a>"
> >        Response.write link
> > %> </body>
> > </html>
> >
> > ----
> >
> > ____________________________________________________
> > Carlos L. LaMar
> > Executive VP, IS & Management Development
> > snyder/newell, inc.
> > > *:   xxx.xxx.xxxx
> > > *:   xxx.xxx.xxxx   (FAX)
> > > *:  clamar@s...
> > > u http://www.snyder-newell.com/
> > >
> > >
> > >
> >
> >
> > ---
> >
> > Improve your web design skills with these new books
> > from Glasshaus.
> >
> > Usable Web Menus
> > http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dn
> osim/theprogramme
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/thepr
> ogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/thepr
> ogramme
> r-20
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> 
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogram
> me
> r-20
> Constructing Accessible Web Sites
> 
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogram
> me
> r-20
> Practical JavaScript for the Usable Web
> 
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogram
> me
> r-20
>

  Return to Index