Friday, September 21, 2007

Enabling file download with asp.net

here's the code for downloading file from web server to client:

// create temporary file
dim strTemp as string = System.IO.Path.GetTempFileName

// here your process for example generating excel file

// here's the code for file download
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment;filename=" & strFileName & ".xls")
Response.Flush()
Response.WriteFile(strTemp)
Response.End

* if your are using asp.net ajax update panel with this code, it will cause problem to the update panel.

the solution can be found here:
Ajax file download and iframe

No comments: