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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Save as' dialog box for text files

Status
Not open for further replies.

cawthor

Programmer
May 31, 2001
89
US
I am generating a text file via ASP. I want to display a 'Save As' dialog box to the user instead of just opening the text file within the browser. I have found a few examples on the web such as:

Response.AppendHeader("content-disposition", "attachment; filename=test.txt")
Response.ContentType = "text/plain"
Response.WriteFile("c:/inetpub/Response.Flush()

All the examples I have found use a variation on the above 'AppendHeader' line, but my browser keeps giving me the following error (referring to that line):

'Cannot use parentheses when calling a Sub'

Any help would be appreciated!

THanks.
 
No ()

Code:
<%
'--------------------------------------------
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName

Const adTypeBinary = 1

strFilePath = "C:\ your path"
strFileSize = ... the size of file .. optional
strFileName = file name
Response.Clear

Requires MDAC 2.5
but MDAC 2.6 or 2.7 is better



Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

strFileType = lcase(Right(strFileName, 4))

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
Response.Charset = "UTF-8"
Response.ContentType = ContentType

Response.BinaryWrite objStream.Read
Response.Flush

objStream.Close
Set objStream = Nothing

%>

www.sitesd.com
ASP WEB DEVELOPMENT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top