Forums

ASP

This topic is locked

search results into csv file for download?

Posted 15 Sep 2003 16:40:44
1
has voted
15 Sep 2003 16:40:44 Sean Johnson posted:
is it possible to download search results to a csv file.

i don't know what the search criteria will be each time as it's from an advanced search form. so can the code that creates such csv file be dynamic?

many thanks in advance

Replies

Replied 16 Sep 2003 10:07:36
16 Sep 2003 10:07:36 Lee Diggins replied:
Hi

It is possible, you need to tell us what web server and which script you using?

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 17 Sep 2003 13:09:53
17 Sep 2003 13:09:53 Sean Johnson replied:
ASP/vbscript on win servers

please also note that i'm using an advacned search form so i won't know what the SQL string should will be (does that make sense??)
Replied 19 Sep 2003 15:39:56
19 Sep 2003 15:39:56 Lee Diggins replied:
Hi Sean

(This post resolved thru email, this is the solution)

Here is the output-to-csv asp file.

I have gone the long way around to show you how this action is performed.

<pre id=code><font face=courier size=2 id=code> &lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;!--#include file="../Connections/SEAN_MDB.asp" --&gt;
&lt;%
Dim rsMyData
Dim rsMyData_numRows

Set rsMyData = Server.CreateObject("ADODB.Recordset"
rsMyData.ActiveConnection = MM_SEAN_MDB_STRING
rsMyData.Source = "SELECT * FROM resource_t"
rsMyData.CursorType = 0
rsMyData.CursorLocation = 2
rsMyData.LockType = 1
rsMyData.Open()

rsMyData_numRows = 0
%&gt;
&lt;%
' Declare variables for use in the csv file creation
Dim strFileName, strTitle, strData, FSO, cFSO, strLoc
strFileName = "myCSVFILE.csv"
strTitle = ""
strData = ""
strLoc = Server.MapPath("." & "\csv_files\" & strFileName

Const fsoForWriting = 2

Set FSO = Server.CreateObject("Scripting.FileSystemObject"
Set cFSO = FSO.OpenTextFile(strLoc ,fsoForWriting ,True)

If Not rsMyData.EOF Then
' assign Title line of csv file to the strTitle variable

strTitle = strTitle & chr(34) & "id_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "title_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "firstname_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "surname_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "address1_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "address2_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "city_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "county_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "postcode_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "postalarea_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "dob_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "gender_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "irsref_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "email_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "hometel_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "mobiletel_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "password_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "fpc3_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "cemap_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "g10_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "g60_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "afpc_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "otherqual_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "cursalary_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "curdayrate_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "curjobtitle_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "prevmanexp_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "prevreviewexp_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "prevqualass_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "workaway_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "lookingfor_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "cv_c" & chr(34) & ","
strTitle = strTitle & chr(34) & "validated_c" & chr(34) & ","

' remove "_c" from the strTitle variable and change to uppercase
strTitle = UCase(Replace(strTitle, "_c", "")

' write the strTitle variable to the first line of the csv file
cFSO.WriteLine(strTitle)

Do Until rsMyData.EOF
' assign data lines of csv file to the strData variable

strData = chr(34) & rsMyData("id_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("title_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("firstname_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("surname_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("address1_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("address2_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("city_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("county_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("postcode_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("postalarea_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("dob_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("gender_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("irsref_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("email_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("hometel_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("mobiletel_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("password_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("fpc3_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("cemap_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("g10_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("g60_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("afpc_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("otherqual_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("cursalary_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("curdayrate_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("curjobtitle_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("prevmanexp_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("prevreviewexp_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("prevqualass_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("workaway_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("lookingfor_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("cv_c" & chr(34) & ","
cFSO.Write(strData)
strData = chr(34) & rsMyData("validated_c" & chr(34) & ","
cFSO.Write(strData)

' write the strData variable to the csv file
cFSO.WriteLine

' move to next record in recordset
rsMyData.MOVENEXT

' repeat until end of recordset
Loop
End If

' do a clean-up
cFSO.Close()
Set cFSO = Nothing
Set FSO = Nothing
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Output CSV File&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Output to CSV File&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;The CSV File - has been created successfully&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="csv_files/&lt;%= strFileName %&gt;"&gt;Click here to view the CSV file&lt;/a&gt;&lt;/p&gt;
&lt;/table&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;%
rsMyData.Close()
Set rsMyData = Nothing
%&gt; </font id=code></pre id=code>

Digga

Sharing Knowledge Saves Valuable Time!!!

Reply to this topic