or
public
class
Person {
public
Person() { }
public
string
FirstName {
get
;
set
; }
public
string
LastName {
get
;
set
; }
public
List<Address> Addresses {
get
;
set
; }
public
List<Phone> Phones {
get
;
set
; }
}
//Method used for rendering the report
public
List<Stream> GenerateTelerik(
string
languageCode =
"en"
)
{
CultureInfo cultureInfo;
cultureInfo = languageCode ==
"fr"
?
new
CultureInfo(
"fr-CA"
) :
new
CultureInfo(
"en-US"
);
// Set the language for static text (i.e. column headings, titles)
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
// Set the language for dynamic text (i.e. date, time, money)
System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
var reportProcessor =
new
Telerik.Reporting.Processing.ReportProcessor();
// set any deviceInfo settings if necessary
var deviceInfo =
new
System.Collections.Hashtable();
var reportviewer =
new
Telerik.Reporting.InstanceReportSource
{
ReportDocument = _reportObject
};
var renderType = getRenderType(_exportFormat);
if
(_exportFormat == ExportFormat.HTML5)
{
deviceInfo[
"OutputFormat"
] = renderType;
string
documentName;
var result = reportProcessor.RenderReport(renderType, reportviewer, deviceInfo, CreateStream,
out
documentName);
if
(result)
{
return
_streams;
}
throw
new
Exception(
"Failed to export to HTML5"
);
}
else
{
var result = reportProcessor.RenderReport(renderType, reportviewer, deviceInfo);
_streams.Add(
new
MemoryStream(result.DocumentBytes));
return
_streams;
}
}
//For Handling multiple streams
Stream CreateStream(
string
name,
string
extension, Encoding encoding,
string
mimeType)
{
string
path = Path.GetTempPath();
string
filePath = Path.Combine(path, name +
"."
+ extension);
FileStream fs =
new
FileStream(filePath, FileMode.Create);
_streams.Add(fs);
return
fs;
}
//And when I want to render the HTML5 to the browser: (method in a controller in MVC application)
private
HttpResponseMessage GetHtml5ResponseMessage(List<Stream> streams, TelerikReporting.ExportFormat exportFormatTyped)
{
string
data =
string
.Empty;
foreach
(var stream
in
streams)
{
StreamReader readStream =
null
;
stream.Position = 0;
readStream =
new
StreamReader(stream);
data += readStream.ReadToEnd();
readStream.Close();
}
return
new
HttpResponseMessage()
{
Content =
new
StringContent(data, Encoding.UTF8, getMIMEType(exportFormatTyped))
};
}