Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Create a downloadable file at run time???

Status
Not open for further replies.

jw424

Programmer
Joined
Aug 7, 2001
Messages
8
Location
US
Hi,

I am new at this vbscript. Please HELP!! Here's what I am trying to do:

I use vbscript to run some SQL code to access the database. I want to put the query result in a file (newly created just as the SQL code is run). I use CreateTextFile to create a file, I can read from and write to that file using objTextStream.read/write methods. But whenever I make a link in html format, (namely, <a href=&quot;myFile.txt&quot;>), the file is not found.

Here's my code:

<%
'some code to run the SQL code, this part is ok
set rs = cnn.Execute(...) 'rs contains the result

dim oFS
Set oFS = CreateObject(&quot;Scripting.FileSystemObject&quot;)

dim oTextStream
Set oTextStream = oFS.CreateTextFile(&quot;temp.txt&quot;)
oTextStream.write rs

'to make sure the file is written:
oTextStream.Close
set oTextStream = oFS.OpenTextFile (&quot;temp.txt&quot;)
dim read
read = oTextStream.ReadAll
Response.write read
%>
'at this point, the output is exactly correct

'to make it a downloadable file
<a href=&quot;temp.txt&quot;>download</a>

But I can never open/download the file.

Any ideas???

--J
 
Have you tried using a fully qualified path name for your file? Wushutwist
 
Hi wushutwist,

I tried using full path name, but it treats the file as a local file on the user's machine when I click on the link to open the file.
 
Sorry I meant when creating the file using the Scripting.FileSystemObject. Where exactly is the file being created? After running the page, go into the OS and do a search for the file and see where it is putting it. If it is not being created in the same directory as the ASP page then the <a href=&quot;temp.txt&quot;>blah,blah</a> will not work because it is a relative address that looks in the directory of the current page. Wushutwist
 
Change the extension to something that the browser will not display itherwise the browser displays it. .TXT is always displayed. Try .TXD or .TDL.
 
When I call CreateTextFile(&quot;temp.txt&quot;), where does temp.txt reside by default? I don't seem to be able to find it anywhere? The funny thing is FileExists(&quot;temp.txt&quot;) returns true, but the link <a href=&quot;temp.txt&quot;> is always not openable.

any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top