From: Anthony Jones on

"S N" <uandme72(a)yahoo.com> wrote in message
news:unVr3cOEJHA.4492(a)TK2MSFTNGP05.phx.gbl...
>I am using the following code to hide the download url of files on my
>website. The code uses Response.Binarywrite to send file to the >client.
>Kindly indicate the maximum size of the file that can be downloaded using
>this method.
>I am hosting this site on a public server, so I will not be able to change
>anything on the webserver. Kindly indicate what can be done to >ensure that
>the above method remains valid for any file size download.
>
>call Response.AddHeader("Content-Disposition","attachment; filename=""" &
>strFileSave & """")
> Response.ContentType = "bad/type"
> Set Fsys = Server.CreateObject("Scripting.FileSystemObject")
> Set TS = Fsys.GetFile(strFile).OpenAsTextStream(1, -1)
> Do While Not (TS.AtEndOfStream)
> Response.BinaryWrite(TS.Read(1))
> Loop

Use this code:-

Sub SendFileToResponse(FilePath, FileName)

Const clChunkSize = 1048576 ' 1MB

Dim oStream, i
Response.Buffer = False

Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", _
"attachment; Filename=" & FileName

Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = 1 ' Binary
oStream.Open
oStream.LoadFromFile FilePath

For i = 1 To oStream.Size \ clChunkSize
Response.BinaryWrite oStream.Read(clChunkSize)
Next
If (oStream.Size Mod clChunkSize) <> 0 Then
Response.BinaryWrite oStream.Read(oStream.Size Mod clChunkSize)
End If
oStream.Close

End Sub

SendFileToResponse strFile, strFileSave

Note the Response.Buffer = false allows you to send a file of any size.

--
Anthony Jones - MVP ASP/ASP.NET

From: S N on
What if we want to use sendfiletoresponse but dont want to force the save as
dialog, instead just want to see the pdf file within the browser window
itself.
is there any change required in the code to achieve this.

"Anthony Jones" <AnthonyWJones(a)yadayadayada.com> wrote in message
news:e5fWrklEJHA.4092(a)TK2MSFTNGP06.phx.gbl...
>
> "S N" <uandme72(a)yahoo.com> wrote in message
> news:unVr3cOEJHA.4492(a)TK2MSFTNGP05.phx.gbl...
>>I am using the following code to hide the download url of files on my
>>website. The code uses Response.Binarywrite to send file to the >client.
>>Kindly indicate the maximum size of the file that can be downloaded using
>>this method.
>>I am hosting this site on a public server, so I will not be able to change
>>anything on the webserver. Kindly indicate what can be done to >ensure
>>that the above method remains valid for any file size download.
>>
>>call Response.AddHeader("Content-Disposition","attachment; filename=""" &
>>strFileSave & """")
>> Response.ContentType = "bad/type"
>> Set Fsys = Server.CreateObject("Scripting.FileSystemObject")
>> Set TS = Fsys.GetFile(strFile).OpenAsTextStream(1, -1)
>> Do While Not (TS.AtEndOfStream)
>> Response.BinaryWrite(TS.Read(1))
>> Loop
>
> Use this code:-
>
> Sub SendFileToResponse(FilePath, FileName)
>
> Const clChunkSize = 1048576 ' 1MB
>
> Dim oStream, i
> Response.Buffer = False
>
> Response.ContentType = "application/octet-stream"
> Response.AddHeader "Content-Disposition", _
> "attachment; Filename=" & FileName
>
> Set oStream = Server.CreateObject("ADODB.Stream")
> oStream.Type = 1 ' Binary
> oStream.Open
> oStream.LoadFromFile FilePath
>
> For i = 1 To oStream.Size \ clChunkSize
> Response.BinaryWrite oStream.Read(clChunkSize)
> Next
> If (oStream.Size Mod clChunkSize) <> 0 Then
> Response.BinaryWrite oStream.Read(oStream.Size Mod clChunkSize)
> End If
> oStream.Close
>
> End Sub
>
> SendFileToResponse strFile, strFileSave
>
> Note the Response.Buffer = false allows you to send a file of any size.
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>


From: Anthony Jones on
"S N" <uandme72(a)yahoo.com> wrote in message
news:%23$Hxh7oEJHA.5448(a)TK2MSFTNGP04.phx.gbl...
> What if we want to use sendfiletoresponse but dont want to force the save
> as dialog, instead just want to see the pdf file within the browser window
> itself.
> is there any change required in the code to achieve this.
>

If you know its a pdf then change content-type to application/pdf and remove
the attachment; keyword from content-disposition.

--
Anthony Jones - MVP ASP/ASP.NET

From: S N on
Following error received:

Response object error 'ASP 0157 : 80004005'
Buffering On

/test/dl.asp, line 2

Buffering cannot be turned off once it is already turned on.


Please note that I am hosting the site on a public server so there is no way
to ask the web admin to configure the server specifically for me. In such a
situation is it possible to eliminate the error as indicated above. Further,
if I am not able to switch off the response.buffer, will there be any
limitation on the size of file that i can download using
response.binarywrite?




"Anthony Jones" <AnthonyWJones(a)yadayadayada.com> wrote in message
news:e94JHNpEJHA.5104(a)TK2MSFTNGP02.phx.gbl...
> "S N" <uandme72(a)yahoo.com> wrote in message
> news:%23$Hxh7oEJHA.5448(a)TK2MSFTNGP04.phx.gbl...
>> What if we want to use sendfiletoresponse but dont want to force the save
>> as dialog, instead just want to see the pdf file within the browser
>> window itself.
>> is there any change required in the code to achieve this.
>>
>
> If you know its a pdf then change content-type to application/pdf and
> remove the attachment; keyword from content-disposition.
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>


From: Anthony Jones on
"S N" <uandme72(a)yahoo.com> wrote in message
news:u4hyiirEJHA.4420(a)TK2MSFTNGP06.phx.gbl...
> Following error received:
>
> Response object error 'ASP 0157 : 80004005'
> Buffering On
>
> /test/dl.asp, line 2
>
> Buffering cannot be turned off once it is already turned on.
>

You get this error if there is anything in your page or includes at the top
of the page which writes stuff to the response before your code has run.
Note any static content in the page will be sent.

Typical a page of this sort looks like:-

<!-- #include .... some common include -->
<%

' Code here that should note writing anything.
'My code I posted to you with your mods.
%>

Where the include is of a similar structure defininng constants and utility
functions.

>
> Please note that I am hosting the site on a public server so there is no
> way to ask the web admin to configure the server specifically for me.

Whilst an admin may have configured the buffer to be on (which is the
default) you can set it off as long as you do so before sending anything.

>In such a situation is it possible to eliminate the error as indicated
>above. Further, if I am not able to switch off the response.buffer, will
>there be any limitation on the size of file that i can download using
>response.binarywrite?
>

Without turning it off there will be a limitation. The is a buffer size
limit that a public server administrator will almost certainly have
configured (the default on IIS6 is 4MB).

--
Anthony Jones - MVP ASP/ASP.NET