Nice way to filter Report Viewers export formats

Thanks to this guy’s article, which shows a decent way to hide reporting service’s export formats from the report viewer, without making global changes to the entire server and such.  If you look at the code, his sample requires a reference to the ReportingServices2005 stuff, so here’s a slight modification of one of his routines which removes that dependency (additionally, we subclassed the ReportViewer itself, but the decorator pattern used in the article is equally compelling): private void ReflectivelySetVisibilityFalse(RenderingExtension extension)
{
FieldInfo info = extension.GetType().GetField(“m_serverExtension”,
BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
{
object actualExtension = info.GetValue(extension);
if (actualExtension != null)
{
PropertyInfo propInfo = actualExtension.GetType().GetProperty(“Visible”);
if (propInfo != null && propInfo.CanWrite)
{
propInfo.SetValue(actualExtension,
false, null);
}
}
}
}

Leave a comment