ASP.Net Exporting dataset/repeater/html to excel

Posted on 2004-12-01
Last Modified: 2012-08-14
I have an application that exports any of the above types to excel using    
response.ContentType = "application/"

Recently the app stopped working, the excel report page flashes on the screen and then disappears.  Is anyone else running into this with IE or IIS upgrades?  These were originally built on Win2000Server recently migrated to Win2003Server.
Question by:Nobletucky2004
    LVL 9

    Expert Comment

    I've recently experienced a similar issue, however I couldn't attribute it to the web server. I found an inconsistency with WinXP SP2 browsers having this issue. I forgot exactly what I was doing, but it was something like redirecting to a different file and then firing a window.close() from javascript. It worked all the time before and then stopped working on XP SP2 machines. I had to add some workaround javascript. I don't know if this is what's happening to you, just sharing my 2 cents. Can you post some more of your sample code?

    Author Comment

        response.Charset = "";
        //set the response mime type for excel
        response.ContentType = "application/";
        //create a string writer
        System.IO.StringWriter stringWrite  = new System.IO.StringWriter();
        //create an htmltextwriter which uses the stringwriter
        System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
        //instantiate a datagrid
        DataGrid dg = new DataGrid();
        //set the datagrid datasource to the dataset passed in
        dg.DataSource = ds.Tables[0];
        //bind the datagrid
        //tell the datagrid to render itself to our htmltextwriter
        //all that//s left is to output the html

    Author Comment

    what type of JavaScript workaround did you use to alleviate this problem?
    LVL 9

    Accepted Solution

    The case I had is that I was popping up a window from the existing window (after some browser detection was done) and i was initially doing this:;

    When this stopped working I had to do this:;

    function fClose(){

    then from the window that popped up I did a:


    This doesn't seem to be your issue though. I'm gonna refer this question to a friend of mine that's more .net savvy

    Author Comment

    Could this have something to do with a setting that is dealing with Trusted Sites.  It seems that when the URL is added to Trusted Sites the files will open in excel, but that presents an issue with having to figure out if users have the URL set in trusted sites, that is rather messy.
    LVL 9

    Expert Comment

    Interesting. Is you IE security set beyond default? Try going into Tools -> Internet Options -> Security and setting the internet zone to the default setting and see what happens.

    Author Comment

    yea, most users that are testing this now have default security settings post an SP2 update.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Windows 10 SmartScreen vs ClickOnce app 5 92
    countEvens challenge 2 48
    bigDiff challenge 17 60
    zeroMAx challenge 20 66
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now