Te pongo un script que uso yo para suministrar facturas, actualizaciones, etc. Este tiene dos parametros: El nombre final que va a tener el archivo (name2) y el archivo original junto con su path (que puedes buscarlo en una BD o tenerlo en una constante) que es name1:
Código:
<%
Response.Buffer = True
Response.Clear
server.ScriptTimeout = 60000
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
name1 = request.QueryString("n1")
name2 = request.QueryString("n2")
strFilePath = ""
strFileName = name1
set FSO = Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(strFileName) then
set oFile = FSO.GetFile(strFileName)
strFileSize = oFile.Size
'Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile(strFileName)
strFileType = right(strFileName, len(strFileName) - instrrev(strFileName, "."))
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
'Para el resto
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename=" & name2
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(objStream.Read)
Response.Flush
objStream.Close
Set objStream = Nothing
else
response.Write("archivo " & strFileName & " no existe")
end if
%>
El propio Script genera el archivo (ya sea .exe, .doc, .loquesea)
http://www.misitio.com/download.asp?n1=factura_0001.doc&n2=c:\misdocs\ff3 45.doc
Modificando un poco el script puedes evitar enviar esa informacion tomandola de otras fuentes
http://www.misitio.com/download.asp?id=34
Donde id puede ser el campo clave de un registro en una tabla que contenga la información pertinente.
RECUERDA QUE EL SCRIPT NO DEBE LLEVAR NINGUN CONTENT-TYPE YA QUE EL MISMO LO GENERA.
Un saludo