Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2006-07-12
3
267 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 18

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

766 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