Description

I am working on a project, where we have to localize rdlc files. Rdlc files are report definition files for reports that are going to be processed locally by the ReportViewer component. My first try was to use some properties in the report, and then set those when the report was to be generated. But then I came to sub-reports, and found that this wasn't really possible. A sub-report can have properties, but I found no way of setting those properties in code. My next take, since all our translated texts are in its own assembly (divided up in a number of resource files), was that maybe I could reference that file directly from the report. I could reference the dll, but for some reason it wouldn't compile. Probably should have been able to make that work somehow, but I didn't care to try that hard.

So I decided to try a new twist, and ended up with this class. Thought others might find it useful, so decided to put it here. So far it has worked great. You might find it useful if:
  • Have your translations in one resource assembly (One dll file with nothing but resource files with public strings)
  • Use local processing and the ReportViewer
  • Can access your report definition files as a stream (Either from a file or from some assembly as an embedded resource)

And if not, you might still find it useful after some modifications, which you are welcome to do. But please let me know if you do. Maybe it was something brilliant that I could learn from too ;)

What it does

  • Takes in a report definition as a stream.
  • Loads the definition into an XDocument object.
  • Replaces all Textbox contents with translations (where it should).
  • Returns the modified report definition as a TextReader, which can be loaded into a ReportViewer.LocalReport.

Example Usage

Stream originalDefinition = {Somehow get the rdlc file as a stream};
reportViewer.LocalReport.LoadReportDefinition(RdlcHelper.Localize(originalDefinition));

Feedback

Since I always want to learn and improve I would appreciate it if you let me know of something that could be done better. Also a general comment if you just found it useful is always nice ;)



Last edited Jan 26, 2009 at 8:24 PM by Svish, version 9