Text file download

This is a discussion on "Text file download" within the Classic ASP section. This forum, and the thread "Text file download are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 5th, 2005, 16:56
New Member
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Text file download

Hallo, i'm a novice. I have, on mi website, a text file. I want to permit the download of it.
If i use this code:
<a href="filemane.txt"><b> Download</b></a>it will be displayed on the screen but not donloaded.
Could someone hel me?
Thanks in advance.
Herlekin
Reply With Quote

  #2 (permalink)  
Old Dec 5th, 2005, 18:08
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,953
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Re: Text file download

There are ways round this. You can either direct people to right click and 'save target as', or you can 'Stream' the file to the browser:-

HTML: Select all
<%
'--------------------------------------------
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
strFilePath = "C:\whatever\folder\"
strFileSize = xxx (optional)
strFileName = the file name 
Response.Clear
'8*******************************8
' Requires MDAC 2.5 to be stable
' I recommend MDAC 2.6 or 2.7
'8*******************************8
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = lcase(Right(strFileName, 4))
' Feel Free to Add Your Own Content-Types Here
Select Case strFileType
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".asp"
ContentType = "text/asp"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select
 
Response.AddHeader "Content-Disposition", "attachment; filename= strFileName
Response.AddHeader "Content-Length", strFileSize
' In a Perfect World, Your Client would also have UTF-8 as the default 
' In Their Browser
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work

Last edited by Rob; Dec 5th, 2005 at 18:12.
Reply With Quote
  #3 (permalink)  
Old Dec 5th, 2005, 18:23
New Member
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Text file download

Taky you, i will tray this way
Reply With Quote
Reply

Tags
text, file, download

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Download button - to download a PDF file attila001122 Web Page Design 4 Aug 15th, 2008 11:44
Allow users to download flv file @lun Flash & Multimedia Forum 4 Jan 29th, 2008 17:33
file download help acrikey Web Page Design 7 Aug 23rd, 2007 00:11
PHP file download script sabatier PHP Forum 2 Aug 14th, 2007 11:43
File Download nileshnaik JavaScript Forum 1 Nov 27th, 2006 16:13


All times are GMT. The time now is 07:25.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43