Hide export 'word' in ReportViewer with ASP.NET.
pageName.aspx
<rsweb:ReportViewer ID="RptTimeLineProcessSummary" runat="server" Width="100%" OnPreRender="RptTimeLineProcessSummary_PreRender">
</rsweb:ReportViewer>
pageName.aspx.cs
protected void RptTimeLineProcessSummary_PreRender(object sender, EventArgs e)
{
DisableUnwantedExportFormats(RptTimeLineProcessSummary.LocalReport);
}
public static void DisableUnwantedExportFormats(LocalReport rvServer)
{
foreach (RenderingExtension extension in rvServer.ListRenderingExtensions())
{
if (extension.Name == "XML" || extension.Name == "WORD" || extension.Name == "MHTML" || extension.Name == "CSV")
{
ReflectivelySetVisibilityFalse(extension);
}
}
}
public static void ReflectivelySetVisibilityFalse(RenderingExtension extension)
{
FieldInfo info = extension.GetType().GetField("m_isVisible", BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
{
info.SetValue(extension, false);
}
}
pageName.aspx
<rsweb:ReportViewer ID="RptTimeLineProcessSummary" runat="server" Width="100%" OnPreRender="RptTimeLineProcessSummary_PreRender">
</rsweb:ReportViewer>
pageName.aspx.cs
protected void RptTimeLineProcessSummary_PreRender(object sender, EventArgs e)
{
DisableUnwantedExportFormats(RptTimeLineProcessSummary.LocalReport);
}
public static void DisableUnwantedExportFormats(LocalReport rvServer)
{
foreach (RenderingExtension extension in rvServer.ListRenderingExtensions())
{
if (extension.Name == "XML" || extension.Name == "WORD" || extension.Name == "MHTML" || extension.Name == "CSV")
{
ReflectivelySetVisibilityFalse(extension);
}
}
}
public static void ReflectivelySetVisibilityFalse(RenderingExtension extension)
{
FieldInfo info = extension.GetType().GetField("m_isVisible", BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
{
info.SetValue(extension, false);
}
}
No comments:
Post a Comment