?
Solved

Help with exporting datagrid to excel

Posted on 2007-10-21
1
Medium Priority
?
728 Views
Last Modified: 2008-01-09
I have the following code and it doesn't work when I'm using a secure connection( https:// ). It works fine when the connection is unsecured (http://)

        Public Shared Sub ExportGridToExcel(ByVal sourceGrid As DataGrid, ByVal FileName As String)
            sourceGrid.GridLines = GridLines.Both
            sourceGrid.HeaderStyle.Font.Bold = True
            sourceGrid.HeaderStyle.ForeColor = Color.Black
            sourceGrid.HeaderStyle.BackColor = Color.Orange

            FileName = FileName.Replace(".xls", "")
            FileName &= ".xls"

            Dim Response As HttpResponse = HttpContext.Current.Response
            Response.Clear()
            Response.AddHeader("content-disposition", "attachment;filename=" & FileName)
            Response.Charset = ""
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.ContentType = "application/vnd.xls"

            Dim stringWrite As New System.IO.StringWriter
            Dim htmlWrite As New HtmlTextWriter(stringWrite)

            ClearControls(sourceGrid)

            sourceGrid.RenderControl(htmlWrite)
            Response.Write(stringWrite.ToString())
            Response.End()
        End Sub
0
Comment
Question by:mattphung
1 Comment
 
LVL 22

Accepted Solution

by:
RedKelvin earned 1500 total points
ID: 20119671
Hi, comment out this line

Response.Cache.SetCacheability(HttpCacheability.NoCache)

Take a look here for more info

http://forums.asp.net/p/980187/1386832.aspx

RedK
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question