Date format doesn't work when exporting report from code

2 posts, 0 answers
  1. vishal
    vishal avatar
    7 posts
    Member since:
    Jun 2010

    Posted 13 Jun 2019 Link to this post

    Issue :

    When report is exported from code, the textbox which displays invoice date do not format the date correctly, The format is set to {0:D}, the result is 01/May/2019 12:00:00 AM.

    When same report is exported from report viewer , the date is formatted correctly, i.e. Monday, April 1, 2019

    Below is code to export report from code.

    Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
    System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
    Telerik.Reporting.TypeReportSource typeReportSource = new Telerik.Reporting.TypeReportSource();
    typeReportSource.TypeName = typeof(FCInvoiceHeader).AssemblyQualifiedName;
    typeReportSource.Parameters.Add("OrderNumber", header.InvoiceNumber);              
    Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", typeReportSource, deviceInfo);
    string fileName = header.InvoiceNumber + "." + result.Extension;
    string path = @"C:\FleetCareBulkInvoice\";
    bool exists = System.IO.Directory.Exists(path);
    if (!exists)
    string filePath = System.IO.Path.Combine(path, fileName);
    using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
         fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
  2. Todor
    Todor avatar
    574 posts

    Posted 18 Jun 2019 Link to this post

    Hello Vishal,

    I tested the provided code snippet in a Console application with sample report displaying the current date formatted with {0:D}. The outcome is as expected both in the Visual Studio Report Designer preview and in the exported PDF. I have attached may test solution. The file 4.PDF in the archive is the programmatically exported report document.
    The problem may be in the report definition. You may send it for local investigation.

    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top