Response.AddHeader("Content-Disposition", "filename=""report.xls""")
if this does not work check out Response.ContentType and check the mime types.
the first line should work for you, although I have used it in conjunction
with Response.BinaryWrite.
Anyways goodluck
"mike" wrote:
> Hi,
> I have surfed through several posting about exporting gridview to excel and
> it works great. using the following code...
> response.Clear()
> response.ContentType = "application/vnd.ms-excel"
> response.Charset = ""
> Dim stringWrite As New System.IO.StringWriter()
> Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
>
> Dim dg As New GridView()
>
> dg.GridLines = GridLines.None
> dg.HeaderStyle.Font.Bold = True
> dg.Datasource = myDataTable
> dg.DataBind()
> 'tell the datagrid to render itself to our htmltextwriter
> dg.RenderControl(htmlWrite)
> 'output the html
> response.Write(stringWrite.ToString)
> response.End()
>
>
> However when response comes to the client it opens excel using Microsoft
> Excel Application instead of inside the Browser. I have following questions...
> 1. How do I make it open inside the browser instead of using MS Excel
> application?
> 2. Is there any way to explicitly instruct the browser to either open inside
> browser or using MS Excel application?
>
> Any sort of guidance on this is greatly appreciated.
> Thanks
> --Mike