I have been trying 2 diferent codes this is one:
nombre="Prueba.txt"
set stream = Server.CreateObject("ADODB.Stream")
stream.Open
stream.Type = 2 ' binary
stream.LoadFromFile(Server.MapPath("./File/"&nombre))
Response.BinaryWrite(stream.Read)
And the other code I'm trying is this :
Response.ContentType = "application/x-unknown" ' arbitrary
FPath = Server.MapPath("./File/"&nombre)
Response.AddHeader "Content-Disposition","attachment; filename=" & nombre
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
ado开发者_运维知识库Stream.LoadFromFile(FPath)
Response.BinaryWrite adoStream.Read()
adoStream.Close
Set adoStream = Nothing
Response.End
And I get that it have found a non especificated/defined data type.
@Giancarlo Solarino: Try this --
Option Explicit
Dim sFileName, sFilePath, iFileSize
Dim oFile, oFS, oStream
sFileName = "Prueba.txt"
sFilePath = Server.MapPath("File/" & sFileName)
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sFilePath) Then
Set oFile = oFS.GetFile(sFilePath)
iFileSize = oFile.Size
Set oFile = Nothing
Response.AddHeader "Content-Disposition","attachment; filename=" & sFileName
Response.ContentType = "application/download"
Response.AddHeader "Content-Length", iFileSize
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.LoadFromFile sFilePath
Do While NOT oStream.EOS AND Response.IsClientConnected
Response.BinaryWrite oStream.Read(1024)
Response.Flush()
Loop
oStream.Close
Set oStream = Nothing
End If
I have some working code, that's pretty much the same, but I use ContentType = "image/jpeg"
and Response.Flush
at the end.
Const adTypeBinary = 1
dim strFileName
strFileName = "archivo.jpg"
dim strFilePath
strFilePath = "C:\temp\" + strFileName
dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Response.Charset = "UTF-8"
Response.ContentType = "image/jpeg"
Response.BinaryWrite objStream.Read
Response.Flush
精彩评论