Computer Science Canada

Error outputting DataGrid to Excel File

Author:  asteffes [ Fri Jul 07, 2006 7:45 am ]
Post subject:  Error outputting DataGrid to Excel File

I am using the code located below to output my datagrid to an excel file.

Everything worked great yesterday, but today there is a problem when you select 'Open' from the "Open, Save, or Cancel" dialogue for the XLS file.

The error looks something like:
"C:\....Temporary Internet Files\....\TimeReport[7].xls' Could not be found. Check spelling and verify location is correct"

I'm guessing that internet explorer is trying to populate an excel sheet that existed yesterday but does not exist today. I've cleared my cookies but it still attempts to fill up these strange excel files.

When I choose the "save" option, it works fine.

Any tips on how to point the code in the right direction when I am opening the excel sheet in a temporary directory?

thanks!

code:

 

Response.Clear()
        Response.AddHeader("content-disposition", "attachment;filename=TimeReport.xls")
        Response.Charset = ""
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.ContentType = "application/vnd.xls"
        Dim stringWrite = New System.IO.StringWriter
        Dim htmlWrite = New HtmlTextWriter(stringWrite)

        dataGrid.RenderControl(htmlWrite)
        Response.Write(stringWrite.ToString())
        Response.End()



: