Response.Writefile error

Mondeo

Centurion
Joined
Nov 10, 2006
Messages
128
Location
Sunny Lancashire
Hi,

I have the following code which generates an Excel document on the fly. I then want to take the file and let the user decide to save it or open it.

Visual Basic:
 Dim xls As New ExcelFile
 Dim fileName As String = xls.Generate()
 Dim file As New IO.FileInfo(fileName)
 Response.Clear()
 Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name)
 Response.AddHeader("Content-Length", file.Length.ToString())
 Response.ContentType = "application/excel"
 Response.WriteFile(file.FullName)
 Response.End()

When it runs I get the egg timer for a few seconds, then the error message icon in the bottom left of the browser appears.

The message is.

The data nessessary to complete the operation is not yet available

Any help appreciated?

Thanks
 
Back
Top