Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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