Add session name to  Response.Add header filename

Ed
Ed used Ask the Experts™
on
|The below code outputs my gridview to excel.

This works fine but I'd like to know how can I add my session variable to the filename.

E.g

Session("Name") gets added to  filename=CaseloadOutput.xls

so it might say filename=Edj_CaseloadOutput.xls



 
  Protected Sub gtnOExcelOutput_Click(sender As Object, e As EventArgs)
        Response.ClearContent()
        Response.AddHeader("content-disposition", "attachment; filename=CaseloadOutput.xls")
        Response.ContentType = "application/excel"
        Dim sw As New System.IO.StringWriter()
        Dim htw As New HtmlTextWriter(sw)
        gvCaseloadExcel.RenderControl(htw)
        Response.Write(sw.ToString())
        Response.[End]()
    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Professional
Top Expert 2015
Commented:
Please try below:

 
Protected Sub gtnOExcelOutput_Click(sender As Object, e As EventArgs)
        Response.ClearContent()

        Response.AddHeader("content-disposition", "attachment; filename="+Session("Name")+"_CaseloadOutput.xls")

        Response.ContentType = "application/excel"
        Dim sw As New System.IO.StringWriter()
        Dim htw As New HtmlTextWriter(sw)
        gvCaseloadExcel.RenderControl(htw)
        Response.Write(sw.ToString())
        Response.[End]()
    End Sub

Open in new window

Ed

Author

Commented:
Perfect, you are the Master....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial