Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7745561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:03:21+00:00 2026-06-01T10:03:21+00:00

I would like to download a .CSV and redirect the user to another page.

  • 0

I would like to download a .CSV and redirect the user to another page.

This is my code

    protected void btnExport_Click(object sender, EventArgs e)
    {
        string attachment = "attachment; filename=" + Request.QueryString["exportName"] + ".csv";
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.AddHeader("content-disposition", attachment);
        HttpContext.Current.Response.ContentType = "application/ms-excel";

        //CODE TO WRITE CSV
        List<Company> companies = (List<Company>)Session["SelectedCompanies"];
        foreach (Company company in companies)
        {
            HttpContext.Current.Response.Write(company.Name + ";");
            HttpContext.Current.Response.Write(Environment.NewLine);
        }



        HttpContext.Current.Response.Redirect("otherpage.aspx", true);


    }

But unfortunatly, it does only the redirect and not the download of the .CSV.

And if I replace HttpContext.Current.Response.Redirect("otherpage.aspx", true); by HttpContext.Current.Response.End();, then it does only the download of the .CSV and not the redirect.

But I would like to have both.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:03:22+00:00Added an answer on June 1, 2026 at 10:03 am

    With such cases, what I do is :

    1. have an iframe hidden

      < iframe id=”DownloadIFrame” visible=”false” width=”1″ height=”1″ style=”display:none” >
      < /iframe >

    2. give this Iframe the url of my downlood (like download.ashx) while changing the content of my page.

    On the server

    public string DownloadViaIFrame(Page page, Download download)
            {
                string script = string.Format(
                @"
                var IsDownloaded=false;
    
                domReady(function() {{
                    if (document.getElementById('DownloadIFrame')==undefined)
                                    alert('DownloadIFrame not found');
                                else
                                {{
                                    if (!IsDownloaded)
                                    {{
                                        {0};
                                        IsDownloaded=true;
                                    }}
                                }}
                }});", GetJavasciptToDownloadViaIFrame(download));
    
    
                ScriptManager.RegisterClientScriptBlock(page, typeof(Page), "download", script, true);
    
                return script;
            }
    
    
     public string GetJavasciptToDownloadViaIFrame(Download download)
            {
                return string.Format("document.getElementById('DownloadIFrame').src='{0}'", GetDownloadLink(download));
            }
    

    this way the Iframe hit the download script on the server and gives back the file to be downloaded by the client. The client at the same time sees the content of its page changed and is happy..

    good luck,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a link that is download a CSV file, I would like
I'm using Yahoo Finance API like this: http://download.finance.yahoo.com/d/quotes.csv?s=GBPEUR=X&f=l1 That gives me the current rates
I would like to download documentation of the Drupal hooks, and whatever else would
I would like to download an mp3 file from some site, save it to
In my app i would like to download images and songs from server url
I would like to implement the download estimator using the JavaScript and the Ajax.
I would like to use standard ASP.NET file download response, like in other Stack
i would like to create a Rails controller that download a serie of jpg
I would like to be able to download a Html5 canvas element as an
I would like to know if it's possible to download a file from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.