Solved

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

Posted on 2006-07-12
3
265 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:
Elvio Lujan 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

11 Experts available now in Live!

Get 1:1 Help Now