Error in IE outputting to Excel

N

Ned Balzer

I have a puzzling problem. I am using some code I found in another
thread here to output the results of a gridview to excel. Here is the
subroutine:

Sub SendToExcel(ByVal Source As Object, ByVal E As EventArgs)
Dim gv As GridView = Ctype(ColRep1Form.FindControl("xlsRep1GridView"),
GridView)
If gv.Rows.Count.ToString + 1 < 65536 Then
gv.AllowPaging = False
gv.AllowSorting = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition",
"attachment;filename=dept1.xls")
Response.Charset = ""
EnableViewState = False
gv.visible= true
gv.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
gv.DataBind()
End If
End Sub

I have a test server and a production server. Both are running Windows
2003 Server (IIS 6). The aspx code is identical on each.

On the test server, this code works, if I use firefox, or if I use IE6
and save the file. On the production server, the code works with
Firefox, but not at all with IE (6 nor 7). In all cases, when I click
the button which invokes this subroutine, I get the dialogue asking me
if I want to open excel or save to a file.

On either server, if I try to open the file from IE, I get an error
message in Excel to the effect that the file in the temp folder
(C:\documents and settings\username\local settings\temporary internet
files\content.ie5\famdomfoldername\dept1.xls) cannot be found. This
sounds a little like a permissions issue, as if IE tried and failed to
save the output stream to a file first before invoking excel to open
it.

If I'm browsing to the test server using IE, I can save the output to a
file and then open it. On the production server, even if I choose
save, I get an error message which reads "Internet Explorer cannot
download deptrep1.aspx from (the name of my site). Internet Explorer
was not able to open this internet site. The requested site is either
unavailable or cannot be found. Please try again later." Deptrep1.aspx
is indeed the name of the aspx page, but I am puzzled because I am not
trying (or at least I think I am not trying) to download it.



The only difference I can see between these servers is that the test
server is using http but the production server requires https. I don't
know if that is significant or not.

Does anyone have any suggestion how to troubleshoot this problem, or
how to make the code more robust to try to avoid any potential
problems? (I have omitted the Else clause in the code because there is
really no chance that the output will exceed 64K rows.) What would be
cool is if the user could either save or open the file, no matter which
browser they use. Barring that, it would be great if I could prevent
the user from having to choose whether to save or open (by making the
correct choice for the user). What is essential is to have something
that works, on the production server, using either firefox or IE.


Thanks.

-- Ned
 

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,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top