Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

RDLC Report Hide Export Option

0.00/5 (No votes)
15 Aug 2010 1  
protected void ReportViewer1_PreRender(object sender, EventArgs e) {DisableFormat(ReportViewer1, Pdf); }protected void

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

protected void ReportViewer1_PreRender(object sender, EventArgs e)

{

DisableFormat(ReportViewer1,
"Pdf");

}

protected void DisableFormat(ReportViewer viewer, string formatName)

{

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;

 

foreach( Object extension in extensions)

{

if (String.Compare(name.GetValue(extension, null).ToString(), formatName, true) == 0 )

{

System.Reflection.
FieldInfo m_isVisible = extension.GetType().GetField("m_isVisible", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

System.Reflection.FieldInfo m_isExposedExternally = extension.GetType().GetField("m_isExposedExternally", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

m_isVisible.SetValue(extension, false);

m_isExposedExternally.SetValue(extension, false) ;

break;

}

}

}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here