This is a migrated thread and some comments may be shown as answers.

Exporting report - Culture problem

2 Answers 121 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Geoffrey
Top achievements
Rank 1
Geoffrey asked on 28 Jul 2015, 08:16 AM
Hello,

I use the following method to export report from console application.
The problem is that the generating report is exported only in default culture (en).
Setting the Thread.CurrentCulture and Thread.CurrentUICulture has no effect.

private void GenerateReportFromSource(InstanceReportSource reportSource, ReportType reportType, String path, CultureInfo cultureInfo)
        {           
            LocalizationInfo.Culture = cultureInfo;
            Thread thread = new Thread(() =>
            {
                try
                {
                   ReportProcessor reportProcessor = new ReportProcessor();
 
                    RenderingResult result = reportProcessor.RenderReport(reportType.ToString().ToUpper(), reportSource, null);
 
                    FileInfo info = new FileInfo(path);
                    if (info.DirectoryName != null && !Directory.Exists(info.DirectoryName))
                        Directory.CreateDirectory(info.DirectoryName);
                    File.WriteAllBytes(path + "." + reportType.ToString().ToLower(), result.DocumentBytes);
                }
                catch (Exception e)
                {
                    Logger.WriteException(e);
                }
            });
            thread.CurrentCulture = cultureInfo;
            thread.CurrentUICulture = cultureInfo;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }

Thanks in advance.

Best regards,
Geoffrey

2 Answers, 1 is accepted

Sort by
0
Geoffrey
Top achievements
Rank 1
answered on 28 Jul 2015, 03:25 PM
I fially solved the problem you shoud say in the documentation that the Report must be instanciate after the Thread.CurrentCulutre* has been setted. I thought that it was the ReportProcessing who manage this.
0
Stef
Telerik team
answered on 30 Jul 2015, 09:41 AM
Hello Geoffrey,

I am glad to hear the issue is resolved.

About setting the culture of the report, Reports localization is standard localization based on resource manager operating with resx files based on the current thread's culture. Thus setting the culture must happen before creating the report instance.

Regards,
Stef
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
Tags
General Discussions
Asked by
Geoffrey
Top achievements
Rank 1
Answers by
Geoffrey
Top achievements
Rank 1
Stef
Telerik team
Share this question
or