Hi Dan,
You need to make sure the browser sees it as an attachment so it will prompt
the user. Here's some code. Let us know if it works for you?
Ken
Microsoft MVP [ASP.NET]
Toronto
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' ************************************************
' Forces a prompted download of a text file
' rather than displaying the text in the browser
' Ken Cox - MVP [ASP.NET]
' September 27, 2004
' ************************************************
' Create a stringbuilder to hold the text to be sent
Dim sb As New System.Text.StringBuilder
' Create a string variable to hold a line of text
Dim strLine As String
'Give the file a name
Dim filename As String = "mytext.txt"
' Get the text file using a stream reader
Dim sr As System.IO.StreamReader = _
New System.IO.StreamReader(Server.MapPath(filename))
' Loop through the text file, line by line
Do
' Read a line of text into the string variable
strLine = sr.ReadLine()
' Add the text content to the stringbuilder
sb.Append(strLine)
' Do this while there's still text
Loop Until strLine Is Nothing
' Close the stream reader
sr.Close()
'Set the appropriate ContentType.
Response.ContentType = "text/plain"
' Add a header telling the browser
' to expect an attachment and give it the
' name of the attachment
Response.AddHeader _
("content-disposition", "attachment; filename=""" & _
filename & """")
'Write the file's content from the stringbuilder
' directly to the HTTP output stream.
Response.Write(sb.ToString)
Response.End()
End Sub
"DanB" <ag*****@kc.rr.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
This is probably soooo simple but I can't seem to get it.
I have a text file that I want users to download via a web page.
I want the file to be saved to a default folder (or one that they choose)
on the users / client file system.
I have toyed with a Self-Extracting zip file but the contents of my zip
file changes each time it is downloaded so that invalidates the exe file.
Also the text file is so small it is a waste to zip it.
The IE:Download behavior looks at the text file and displays in the
browser.
I've look at client-side scripting using the FileSystem object but I can't
seem to get FSO to open the file on the server. Does anyone know can FSO
open a file or copy a file from the server to the client?
Ftp is always a possibility but how do I get it saved to the client after
it is downloaded?
This should be simple. What direction should I head here?