Response.ContentType not working ???

A

Adrian Turner

The following code just outputs to the browser, I want it to download and I
dont understand why it doesnt work....

Sub Page_Load(Sender As Object, E As EventArgs)
Page.EnableViewState=False
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition","attachment; filename=test.xls")
Response.write("Adrian")
Response.end()
end sub

Very annoying, should be simple. Any help would be appreciated.

Ade
 
S

Scott M.

Adrian Turner said:
The following code just outputs to the browser, I want it to download and
I
dont understand why it doesnt work....

Sub Page_Load(Sender As Object, E As EventArgs)
Page.EnableViewState=False
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition","attachment; filename=test.xls")
Response.write("Adrian")
Response.end()
end sub

Very annoying, should be simple. Any help would be appreciated.

Ade

Where is this code placed? How are you trying to test the code?

-Scott
 
G

Gregory A. Beamer

The following code just outputs to the browser, I want it to download
and I dont understand why it doesnt work....

Sub Page_Load(Sender As Object, E As EventArgs)
Page.EnableViewState=False
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition","attachment;
filename=test.xls") Response.write("Adrian")
Response.end()
end sub

Very annoying, should be simple. Any help would be appreciated.


As you have given no context to the application, the version of IIS, the
browser type, I can give you little input. It could be a MIME type
issue, for example, but I cannot tell from the example you have given.

Peace and Grace,
 
P

Patrice

The following code just outputs to the browser, I want it to download and
I
dont understand why it doesnt work....

Works fine here... Could it be a cache related issue ?

As a side note, another option is to use an AXD handler (but an ASPX page
should work as well, I just mention this as it avoids the little extra cost
caused by the page infrastructure but it's likely doesn't matter unless you
have a heavily loaded site).
 
S

Scott M.

Patrice said:
Works fine here... Could it be a cache related issue ?

As a side note, another option is to use an AXD handler (but an ASPX page
should work as well, I just mention this as it avoids the little extra
cost caused by the page infrastructure but it's likely doesn't matter
unless you have a heavily loaded site).

Since the OP stated that he's actually seeing the code for his page in the
results, it makes me think the file is not being requested (and therefore
not being served up) correctly.

-Scott
 
P

Patrice

Good point. I thought he meant that the code just outputs "Adrian" to the
browser, not that the whole code is displayed in the browser...
 
S

Scott M.

On second look, maybe he does mean that. Hard to tell. He needs to provide
more info.

-Scott
 
A

Andrew Morton

Adrian said:
The following code just outputs to the browser, I want it to download
and I dont understand why it doesnt work....

What, as if the browser is set to always open the file and not ask?

Perhaps try a different browser if you can't find where to reset that
browser option.

Andrew
 

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,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top