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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:05:28+00:00 2026-06-07T14:05:28+00:00

This might be a simple one but here goes: I’m implementing an excel downloadable

  • 0

This might be a simple one but here goes:

I’m implementing an excel downloadable report in my MVC3 application. I’ve used this method in the past and it’s worked perfectly, however in this case, there is a chance that sales data may not exist for the report. Here is my code:

I have a FileResult action within a Reports controller:

    [HttpPost]
    public FileResult ExcelReportDownload(ReportExcelDownloadRequest reportRequest)
    {
        ReportEngine re = new ReportEngine();

        Stream report = re.GetReport(reportRequest);

        return new FileStreamResult(report, "application/ms-excel")
        {
            FileDownloadName = "SalesReport.xls"
        };
    }

My issue is that sometimes the report stream may be null meaning that there’s no sales info available, in which case I would rather redirect to a View that displays a message to say there is no sales information available, however I am not sure how to achieve this.

Is there a way to do this?

  • 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-07T14:05:29+00:00Added an answer on June 7, 2026 at 2:05 pm

    Well, FileResult inherits from ActionResult :

    If you result can be either a RedirectToRouteResult (inheriting from ActionResult) or a FileResult, then… your action must be of type ActionResult, which can manage both.

    something like that :

        [HttpPost]
        public ActionResult ExcelReportDownload(ReportExcelDownloadRequest reportRequest)
        {
            ReportEngine re = new ReportEngine();
    
            Stream report = re.GetReport(reportRequest);
            if (report == null)
               return RedirectToAction(<action Name>);
            else
               return new FileStreamResult(report, "application/ms-excel")
               {
                   FileDownloadName = "SalesReport.xls"
               };
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a simple one, but since I don't have much knowledge about
This might be simple one but I am finding it very difficult to work
This might be simple but I am new to Oracle. I am using Oracle
Ok, this might sound simple but am not sure what to do. I am
This might be a simple question but I've searched and searched and can't find
This might be a simple question, but i can't seem to grasp it. I
This might be a simple answer, but I am having some issues writing this
This might be a simple question but I'm just picking this up so please
This might seem ridiculously simple, but I've been getting all kinds of error depending
Sorry this might be a simple question, but I could not figure it out.

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.