This project has moved. For the latest updates, please go here.

Downloading the generated file instead of saving

Sep 11, 2013 at 10:59 AM
Is there a way of downloading the generated Excel file instead of saving it somewhere? i.e. as soon as a user clicks the link to generate the Excel file it prompts for it to be downloaded? The user can save it to wherever they want
Sep 11, 2013 at 11:31 AM
Found it! In case anyone else wondered
HttpContext.Current.Response.Clear()
        HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=AddingDataSet.xlsx")

        Using memoryStream As New MemoryStream()
            workbook.SaveAs(memoryStream)
            memoryStream.WriteTo(HttpContext.Current.Response.OutputStream)
            memoryStream.Close()
        End Using

        HttpContext.Current.Response.[End]()