Solved

Problem Exporting Gridview To Excel: No prompt to download Please Help!!! (VB)

Posted on 2006-07-12
3
264 Views
Last Modified: 2008-02-26
I'm trying to export a gridview to excel. However, Internet Explorer constantly opens the file rather than giving me the choice to download it resulting in my computer slowing down signifigantly as it tries to load all the data.  I've tried resetting both the security and advanced settings within IE and nothing seems to work, which leads me to think it might be my code.

Here is my export code:

In Export.aspx:

Protected Sub On_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim TempAccessDataSource As New AccessDataSource

        TempAccessDataSource.DataFile = strDatabasePath

        TempAccessDataSource.SelectCommand = Session("SelectCommand")
        Session("SelectCommand") = Nothing
        Session.Remove("SelectCommand")


        'create table to export to excel
        Dim NewGridView As New GridView()
        NewGridView.DataSource = TempAccessDataSource
        NewGridView.DataBind()
        Dim oStringWriter As New System.IO.StringWriter()
        Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)

        'export to excel
        Response.Clear()
        Response.Charset = ""
        Response.ContentEncoding = System.Text.Encoding.ASCII
        Response.Buffer = True
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("Content-Disposition", "inline;filename=ExcelDownload.xls")
        NewGridView.RenderControl(oHtmlTextWriter)
        Response.Write(oStringWriter.ToString())
        Response.End()

        'clean up
        NewGridView.Dispose()
        TempAccessDataSource.Dispose()

    End Sub

The


I appreciate any help on this matter as this problem is draining away my productivity.


I'm sorry if I put this question in the wrong topic area, I was unsure weather or not the problem lay in my code or with IE so I errored on the side of caution and placed it here.
0
Comment
Question by:rderveloy
3 Comments
 
LVL 17

Accepted Solution

by:
lem2802 earned 300 total points
ID: 17091598
run gpedit.msc...

and go to:

User configutration - Administrative templates - Windows components - Internet Explorer - Internet control panel - Security page - Internet zone

and set "automaticly ask before to download a file" to enabled

may be the names are not the same... because i have the spanish windows... but try to find them! :)
0
 
LVL 14

Assisted Solution

by:Ramuncikas
Ramuncikas earned 200 total points
ID: 17091730
Change to
   Response.ContentType = "application/download"
   -or-
   Response.ContentType = "application/unknown"
0
 

Author Comment

by:rderveloy
ID: 17133911
Thanks for the help!

I tried the modified code and it didn't seem to do anything.

The final solution was to use the gpedit.msc trick as well as the following:

Within windows explorer, go to Tools -> Folder Options.  Click the file types tab.  Select "XLS Microsoft Excel Worksheet" and click advanced.  Place a check in the box labled "Confirm open after download," click ok, then click close.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now