
Signature
Anthony Jones - MVP ASP/ASP.NET
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?
>> 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
[quoted text clipped - 3 lines]
> If you know its a pdf then change content-type to application/pdf and
> remove the attachment; keyword from content-disposition.
Anthony Jones - 09 Sep 2008 21:25 GMT
> Following error received:
>
[quoted text clipped - 4 lines]
>
> 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).

Signature
Anthony Jones - MVP ASP/ASP.NET
Also advise the content type in case the file is an excel file, word
document, exe file, zip file etc.
Thanks in advance.
>> 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
[quoted text clipped - 3 lines]
> If you know its a pdf then change content-type to application/pdf and
> remove the attachment; keyword from content-disposition.
Anthony Jones - 09 Sep 2008 21:47 GMT
> Also advise the content type in case the file is an excel file, word
> document, exe file, zip file etc.
Try Google: mime type xxx where xxx = doc, exe etc.

Signature
Anthony Jones - MVP ASP/ASP.NET
S N - 09 Sep 2008 22:14 GMT
Got it. But now a new problem.
When I place <%Response.Buffer=False%> as the first line of my asp file, no
file is downloaded and no message comes.
However, when I delete the <%Response.Buffer=False%> line then the file
downloads as expected.
Please advise.
>> Also advise the content type in case the file is an excel file, word
>> document, exe file, zip file etc.
>
> Try Google: mime type xxx where xxx = doc, exe etc.
S N - 09 Sep 2008 22:16 GMT
Also I am linking the download code from another file. When I run the
download code without referring to it from another file, it runs. But When I
refer it from another file and it has <%Response.Buffer=False%> line, then I
get the message
Response object error 'ASP 0156 : 80004005'
Header Error
/test/dl.asp, line 114
The HTTP headers are already written to the client browser. Any HTTP header
modifications must be made before writing page content.
Please help
>> Also advise the content type in case the file is an excel file, word
>> document, exe file, zip file etc.
>
> Try Google: mime type xxx where xxx = doc, exe etc.
S N - 09 Sep 2008 22:33 GMT
I got it finally. Thanks.
Just one clarification
You intended
For i = 1 To oStream.Size / clChunkSize
or
For i = 1 To oStream.Size \ clChunkSize
Please clarify.
> Also I am linking the download code from another file. When I run the
> download code without referring to it from another file, it runs. But When
[quoted text clipped - 15 lines]
>>
>> Try Google: mime type xxx where xxx = doc, exe etc.
Old Pedant - 10 Sep 2008 03:00 GMT
> Just one clarification
> You intended
> For i = 1 To oStream.Size / clChunkSize
> or
> For i = 1 To oStream.Size \ clChunkSize
He *intended* the latter.
The backslash operator means "integer division" in VBScript (and VB and
VB.NET) code.
That is,
a \ b
is equivalent to
INT( a / b )
********************
Also, you don't need to mess with Response.Buffer=False, at all.
Just follow each
Response.BinaryWrite
with
Response.Flush
Now the buffer will never get more full than one "chunkSize".
Anthony Jones - 10 Sep 2008 21:02 GMT
>> Just one clarification
>> You intended
[quoted text clipped - 22 lines]
>
> Now the buffer will never get more full than one "chunkSize".
Yes that would work. However it would mask unintended errors that turning
the buffer off right at the top of the code exposes.

Signature
Anthony Jones - MVP ASP/ASP.NET
S N - 13 Sep 2008 14:41 GMT
>>> Just one clarification
>>> You intended
[quoted text clipped - 25 lines]
> Yes that would work. However it would mask unintended errors that turning
> the buffer off right at the top of the code exposes.
what kind of errors would be exposed by turning off the buffer. kindly
elaborate.
Anthony Jones - 13 Sep 2008 21:14 GMT
>>>> Just one clarification
>>>> You intended
[quoted text clipped - 28 lines]
> what kind of errors would be exposed by turning off the buffer. kindly
> elaborate.
Well the sort of problems you've discovered where you may unintentionaly be
placing things in the output buffer that you didn't want present. Example:-
<!-- #include /virtual="/someinclude.asp" -->
<%
Response.ContentType = "application/octet-stream"
Do Until ....
Response.BinaryWrite SomeStuff
Response.Flush
Loop
%>
'someinclude.asp
<!-- Ooops some accidental static content here -->
<%
'utility code
%>
Placing a Response.Buffer at the top of your page would barf immediately on
that line alerting you to a problem.
It also saves you having to remember to Response.Flush if you have multiple
places where you write to the buffer.

Signature
Anthony Jones - MVP ASP/ASP.NET