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

  • SEARCH
  • Home
  • 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 7195925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:40:41+00:00 2026-05-28T20:40:41+00:00

I have the following action inside my Controller public ActionResult DownloadExcel() { //create and

  • 0

I have the following action inside my Controller

public ActionResult DownloadExcel()
        {
            //create and populate Excel file here
            C1XLBook testBook = new C1XLBook(); 
            //populate it here

            MemoryStream ms = new MemoryStream();
            testBook.Save(ms, FileFormat.Biff8);

            return File(ms, "application/ms-excel", "test-file.xls");           
        }

When opening the file, I get the Excel message saying that the file doesn’t match the extension and the file opens up corrupted.

If I save the file on the hard drive and return it from there, everything is fine:

return base.File(@"C:\LOGS\test-file.xls", "application/ms-excel", "test-excel.xls");

I initially thought that the Save function corrupts it when saving it into the MemoryStream, so I saved and re-loaded it back and it was fine passing back to the user – when saved on the Hard Drive and returned from there, rather than from the MemoryStream

Any ideas? I am not too fond of saving the file on the Hard Drive….besides I should be able to save it into the MemoryStream and return it from there?

One hunch I have is that perhaps the MemoryStream should not be used to return files in MVC, since every request is isolated?

  • 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-05-28T20:40:42+00:00Added an answer on May 28, 2026 at 8:40 pm

    Perhaps you need to rewind the memory stream (set ms.Position = 0;) before passing it to the result? After the call to Save its position will be at the end, not the beginning.

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

Sidebar

Related Questions

Inside my controller's action I have the following code: public ActionResult GridAction(string id) {
I have following code: public static void ProcessStep(Action action) { //do something here if
I have a controller with the following action code: public JsonResult CheckPasswordStrength(string password, string
I have the following controller action and test. I'm new to testing with Shoulda
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have the following route defined routes.MapRoute( ItemName, {controller}/{action}/{projectName}/{name}, new { controller = Home,
I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have the following ActionLink in my view <%= Html.ActionLink(LinkText, Action, Controller); %> and
MVC 3. VB.NET I have the following controller action in my application to send
I have the following code inside my UIViewController - [flipButton addTarget:self.navigationController.delegate action:@selector(changeModeAction:) forControlEvents:UIControlEventTouchUpInside]; As

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.