This is a migrated thread and some comments may be shown as answers.
Date format doesn't work when exporting report from code
1 Answer 19 Views
This is a migrated thread and some comments may be shown as answers.
vishal
Top achievements
Rank 1
vishal asked on 14 Jun 2019, 01:18 AM

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)
   System.IO.Directory.CreateDirectory(path);
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);
}

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 18 Jun 2019, 01:38 PM
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.

Regards,
Todor
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
Asked by
vishal
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or