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 8382055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:50:38+00:00 2026-06-09T16:50:38+00:00

I display a table with data on the page and then when user clicks

  • 0

I display a table with data on the page and then when user clicks Export I put the data in the excel file. Now I want to open this file so that user can save it or just view it. This is the code I have. It prompts the user to save a file but that file is the whole page!! WHat is wrong here?

   string filename = filePath.Substring(12);
                        System.IO.File.Copy(filePath, "C:/Work/MCTestSuiteCertificate/TS.ToDoViewer/Content/" + filename, true);
                        Response.Clear();
                        Response.ContentType = @"application\xls";
                       // FileInfo file = new FileInfo(Server.MapPath("~/Content/" + filename));
                        Response.AddHeader("Filename", filename);
                        Response.ContentType = "application/xls";
                        Response.TransmitFile("C:/Work/MCTestSuiteCertificate/TS.ToDoViewer/Content/" + filename);
                        //Response.WriteFile(file.FullName);
                        Response.Flush();
  • 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-09T16:50:40+00:00Added an answer on June 9, 2026 at 4:50 pm

    Use File method (which returns FileResult). You should not work directly with Response in MVC application.

    public ActionResult YourAction()
    {
        ...
        string filename = filePath.Substring(12);
        return File(Path.Combine(@"C:\Work\MCTestSuiteCertificate\TS.ToDoViewer\Content", filename), "application/xls");
    }
    

    PS Also please note use of Path.Combine instead of string concatenation.

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

Sidebar

Related Questions

I have a long list of data that I want to display in table
Many applications have grids that display data from a database table one page at
I use php to display a table of data drawn from my mysql database.
I am trying to display a table containing data from my db in a
Are there any implementations to display nicely table or list data in c# console
I'm using the W3 Schools example: http://www.w3schools.com/PHP/php_ajax_database.asp to display a table of database data
I have a data table with many rows and columns. How can I display
if there is no data to display, jsf data table shows headers only. How
I'm trying to inherit QSqlTableModel to make data im my table display in way
I have some data that I have to display as a table. I think

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.