This project has moved and is read-only. For the latest updates, please go here.

Write report to disk

Jun 20, 2012 at 10:44 AM


Using Doddle MVC ReportResult() is there a way to write the generated report to the web server hard disk instead of serving it to the client?

I'd like to pre-publish reports for the user as some of my reports can take a long time to pull their required data!



Jul 31, 2012 at 5:25 PM

Just though i would give this a nudge - has ANYONE got any suggestions for this?



Jul 31, 2012 at 6:10 PM

Hi fillus, i don't know if this helps

public ActionResult Index()
            string file = @"C:\......."
            var query = DoddleProductRepository.GetAll();
            var totalProducts = query.Count;
            var totalOrders = query.Sum(p => p.OrderCount);

            // Create the report and turn our query into a ReportSource
            var report = new Report(query.ToReportSource());

            // Customize the Text Fields
            report.TextFields.Title = "Products Report";
            report.TextFields.SubTitle = "This is a sample report showing how Doddle Report works";
            report.TextFields.Footer = "Copyright 2011 (c) The Doddle Project";
            report.TextFields.Header = string.Format(@"
                Report Generated: {0}
                Total Products: {1}
                Total Orders: {2}
                Total Sales: {3:c}", DateTime.Now, totalProducts, totalOrders, totalProducts * totalOrders);

            IReportWriter writer = new DoddleReport.OpenXml.ExcelReportWriter();

            using (FileStream fs = new FileStream(file, FileMode.Create))
                writer.WriteReport(report, fs);

            return View();
It's just an idea. You generate the report as you always do but you don't return a ReportResult, you write the report to de server HD and then you return a view or whatever you want informing the report was generated. Is it what you nedeed??? (Sorry for my english)

Jul 31, 2012 at 8:16 PM

Thanks for helping out Snekkke, your solution is indeed correct. The IReportWriter's can write to any Stream instance. If you open a FileStream you can tell the Writer to push it's data to it, which would create the file.


In the source code there is a DoddleReport.Sample.WinForms which shows this idea:

            using (var stream = File.Create("Report.xlsx"))
Aug 1, 2012 at 9:37 AM

Hi Snekkke and mhidinger - thanks for taking the time to reply

The solution you offered is exactly what i'm looking for - hopefully will help some others too

thanks again