Export to excel 2007 using server side code RRS feed

  • Question

  • I am trying to export a grid to excel sheet 2007 .
    I am using following code
    Dim gvExport As New GridView
                Dim swExport As New StringWriter
                Dim htwExport As New HtmlTextWriter(swExport)
                HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
                HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename=ArchivedTasks.xls"))
                gvExport.DataSource = dsTaskList

    while opening the excel sheet , I am geting a prompt box with error msg as "The file you are trying to open is in different format than specified by file extension , verify that file is not corrupted and is from a trusted source before opening the file . Do you want to continue?"

    And if I click yes , it is open the file with .xls extension.
    How can i avoid the prompt message and also open the file with .xslx file extension.

    Thanks in advance.
    • Moved by nobugz Wednesday, April 22, 2009 3:08 PM forums.asp.net
    Wednesday, April 22, 2009 2:30 PM