Hide export format in RDLC/SSRS Report Viewer control
I recently needed to hide or disable PDF format in Export Formats dropdown list displayed in SSRS ReportViewer’s toolbar in Local Report mode.
Unfortunately, ReportViewer control has no method or property to manage specific format’s visibility and this is true also for the recently released Report Viewer 10.
We can use Report Viewer’s property ShowExportControls to hide the export formats dropdown list but not a specific format such as PDF.
In Local Report mode, there are 2 export formats (Excel and PDF) and more Rendering Extensions for Server Report mode are available.
We have the option to hide export formats control and implement our own list. this article might help on this.
Finally, I ended up with adding new extension method SetExportFormatVisibility to ReportViewer control which uses private Reflection to disable/enable export formats.
This method is inspired by Stephen Songer’s blog post Disable/Enable export format in SSRS and ASP.NET.
The code consists of two parts, one is ReportViewerExtensions class which has SetExportFormatVisibility extension method and the second is ReportViewerExportFormat Enum to specify available export formats.
public static class ReportViewerExtensions
{
public static void SetExportFormatVisibility(this ReportViewer viewer, ReportViewerExportFormat format, bool isVisible)
{
string formatName = format.ToString();
const System.Reflection.BindingFlags Flags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance;
System.Reflection.FieldInfo m_previewService = viewer.LocalReport.GetType().GetField("m_previewService", Flags);
System.Reflection.MethodInfo ListRenderingExtensions = m_previewService.FieldType.GetMethod("ListRenderingExtensions", Flags);
object previewServiceInstance = m_previewService.GetValue(viewer.LocalReport);
IList extensions = (IList)ListRenderingExtensions.Invoke(previewServiceInstance, null);
System.Reflection.PropertyInfo name = extensions[0].GetType().GetProperty("Name", Flags);
//object extension = null;
foreach (var ext in extensions)
{
if ((string.Compare(name.GetValue(ext, null).ToString(), formatName, true) == 0))
{
System.Reflection.FieldInfo m_isVisible = ext.GetType().GetField("m_isVisible", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
System.Reflection.FieldInfo m_isExposedExternally = ext.GetType().GetField("m_isExposedExternally", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
m_isVisible.SetValue(ext, isVisible);
m_isExposedExternally.SetValue(ext, isVisible);
break;
}
}
}
}
public enum ReportViewerExportFormat
{
Excel,
PDF
}
Simple to use..
ReportViewer1.SetExportFormatVisibility(ReportViewerExportFormat.PDF, false);



