Downloading files

T

tshad

I have some code to allow me to send text files to my user. I am not
allowing them to view my directory. I am just downloading a file they
previously requested, which works some of the time.

Dim fs As FileStream
Dim strContentType As String
Dim strPath = "C:\My External\File Path\"
Dim strFileName As String = "TomsTest.txt"
fs = File.Open(strPath & strFileName, FileMode.Open)
Dim bytBytes(fs.Length) As Byte
fs.Read(bytBytes, 0, fs.Length)
fs.Close()
Response.AddHeader("Content-disposition", _
"attachment; filename=" & strFileName)
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(bytBytes)
Response.End()

If I run this on an XP and the user has Automatic downloads of files
disabled, the user will get a blank page with all the text displaying on it.

If it is enabled, I get the Save As prompt and allows the user to save the
file.

This can be confusing to the user. Is there a way for me to know if the
user will have a problem with the download?

This is not an automatic download, the user is actually pushing a button
saying he wants to download the file.

Thanks,

Tom
 
K

Kevin Spencer

Your bes bet would be to write a custom HttpHandler for delivering .txt
files.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top