Hello,
it is very important for me to enable export data from ReportViewer to CSV format in LocalReport (which is possible by default in server mode). In ReportViewer 2008 there is an interface called IRenderingExtension, which allows to write a custom export code. The following method allows to add an own class to enable export to custom format:
public static void AddRenderingExtension(ReportViewer viewer, string formatName, Type renderingExtension)
{
const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
FieldInfo m_previewService = viewer.LocalReport.GetType().GetField
(
"m_previewService",
Flags
);
MethodInfo ListRenderingExtensions = m_previewService.FieldType.GetMethod
(
"ListRenderingExtensions",
Flags
);
object previewServiceInstance = m_previewService.GetValue(viewer.LocalReport);
Type type = Type.GetType("Microsoft.Reporting.LocalRenderingExtensionInfo, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
ConstructorInfo ctor = type.GetConstructor
(
BindingFlags.NonPublic | BindingFlags.Instance,
null,
new Type[] { typeof(string), typeof(string), typeof(bool), typeof(Type), typeof(bool) },
null
);
IList extensions = ListRenderingExtensions.Invoke(previewServiceInstance, null) as IList;
object instance = ctor.Invoke(new object[]
{
formatName,
formatName,
true,
renderingExtension,
true
});
extensions.Add(instance);
}
The call of this method looks like AddRenderingExtension(reportViewer, "CSV", typeof(IRenderingExtensionDerivedClass));
Everything works very well in ReportViewer 2008 (CSV export option appears in ReportViewer's export comboBox), but there is a problem in ReportViewer 2010 - IRenderingExtension was moved to namespace Microsoft.ReportingServices.OnDemandReportRendering and it is not public any more! (Visual Studio says, that IRenderingExtension is inaccessible due to its protecion level).
Is there any way to add a custom (CSV) export extension to ReportViewer 2010 in LocalReport?
Regards, Jacek