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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:31:06+00:00 2026-05-21T14:31:06+00:00

I’m looking for some advice. I’m building on an additional feature to a C#

  • 0

I’m looking for some advice. I’m building on an additional feature to a C# project that someone else wrote. The solution of the project consists of an MVC web application, with a few class libraries.

What I’m editing is the sales reporting function. In the original build, a summary of the sales reports were generated on the web application. When the user generates the sales report, a Reporting class is called in one of the C# class libraries. I’m trying to make the sales reports downloadable in an excel file when the user selects a radio button.

Here is a snippet of code from the Reporting class:

public AdminSalesReport GetCompleteAdminSalesReport(AdminSalesReportRequest reportRequest)
        {
            AdminSalesReport report = new AdminSalesReport();
            string dateRange = null;
            List<ProductSale> productSales = GetFilteredListOfAdminProductSales(reportRequest, out dateRange);

            report.DateRange = dateRange;

            if (titleSales.Count > 0)
            {
                report.HasData = true;

                report.Total = GetTotalAdminSales(productSales);

                if (reportRequest.Type == AdminSalesReportRequest.AdminSalesReportType.Complete)
                {
                    report.ProductSales = GetAdminProductSales(productSales);

                    report.CustomerSales = GetAdminCustomerSales(productSales);

                    report.ManufacturerSales = GetAdminManufacturerSales(productSales);

                    if (reportRequest.Download)
                    {
                        FileResult ExcelDownload = GetExcelDownload(productSales);
                    }

                }
            }

            return report;
        }

So as you can see, if reportRequest.Download == true, the class should start up the process of creating the excel file. All the GetAdminSales functions do it use linq queries to sort out the sales if they are being displayed on the webpage.

So I have added this along with the GetAdminSales functions:

private FileResult GetExcelDownload(List<TitleSale> titleSales)
{
    CustomisedSalesReport CustSalesRep = new CustomisedSalesReport();

    Stream SalesReport = CustSalesRep.GenerateCustomisedSalesStream(productSales);

    return new FileStreamResult(SalesReport, "application/ms-excel")
    {
        FileDownloadName = "SalesReport" + DateTime.Now.ToString("MMMM d, yyy") + ".xls"
    };
}

and to format the excel sheet, I’m using the NPOI library, and my formatter class is laid out like so:

public class CustomisedSalesReport
    {
        public Stream GenerateCustomisedSalesStream(List<ProductSale> productSales)
        {
            return GenerateCustomisedSalesFile(productSales);
        }

        private Stream GenerateCustomisedSalesFile(List<ProductSale> productSales)
        {
            MemoryStream ms = new MemoryStream();
            HSSFWorkbook templateWorkbook = new HSSFWorkbook();

            HSSFSheet sheet = templateWorkbook.CreateSheet("Sales Report");

            HSSFRow dataRow = sheet.CreateRow(0);
            HSSFCell cell = dataRow.CreateCell(0);

            cell = dataRow.CreateCell(0);
            cell.SetCellValue(DateTime.Now.ToString("MMMM yyyy") + " Sales Report");

            dataRow = sheet.CreateRow(2);

            string[] colHeaders = new string[] {
                "Product Code",
                "Product Name",
                "Qty Sold",
                "Earnings",
            };

            int colPosition = 0;

            foreach (string colHeader in colHeaders)
            {
                cell = dataRow.CreateCell(colPosition++);
                cell.SetCellValue(colHeader);
            }

            int row = 4;

            var adminTotalSales = GetAdminProductSales(productSales);


            foreach (SummaryAdminProductSale t in adminTotalSales)
            {
                dataRow = sheet.CreateRow(row++);
                colPosition = 0;

                cell = dataRow.CreateCell(colPosition++);
                cell.SetCellValue(t.ProductCode);

                cell = dataRow.CreateCell(colPosition++);
                cell.SetCellValue(t.ProductName);

                cell = dataRow.CreateCell(colPosition++);
                cell.SetCellValue(t.QtySold);

                cell = dataRow.CreateCell(colPosition++);
                cell.SetCellValue(t.Total.ToString("0.00"));
            }

            }
        templateWorkbook.Write(ms);
        ms.Position = 0;

            return ms;

        }

Again like before, the GetAdminSales (GetAdminProductSales, etc) are contained in the bottom of the class, and are just linq queries to gather the data.

So when I run this, I don’t get any obvious errors. The summary sales report appears on screen as normal but no excel document downloads. What I have done, which may be putting this off is in my class library I have referened the System.Web.Mvc dll in order to download the file (I have not done it any other way before – and after reading up on the net I got the impression I could use it in a class library).

When I debug through the code to get a closer picture of what’s going on, everything seems to be working ok, all the right data is being captured but I found that from the very start – the MemoryStream ms = new Memory Stream declaration line in my formatter class shows up this (very hidden mind you) :

ReadTimeout ‘((System.IO.Stream)(ms)).ReadTimeout’
threw an exception of type
‘System.InvalidOperationException’ int
{System.InvalidOperationException}

+{“Timeouts are not supported on this stream.”} System.SystemException
{System.InvalidOperationException}

I get the same for ‘WriteTimeout’…

Apologies for the long windedness of the explaination. I’d appreciate it if anyone could point me in the right direction, either to solve my current issue, or an alternative way of making this work.

  • 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-21T14:31:06+00:00Added an answer on May 21, 2026 at 2:31 pm

    Without getting bogged down in the details, the obvious error is that in GenerateCustomisedSalesFile you create a MemoryStream ms, do nothing with it, then return it.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but

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.