locked
ReportViewer 2010:how to hide pdf in export option in subreports in reportviewer RRS feed

  • Question

  • Hi,
    I am using ReportViewer 2010 and using code (posted below) to hide certain options from export, its working fine for parent report,  but when i am clicking on parent report to view child report, then export option in child report is showing all the items in export option which all are hided in parent report. So please help me out.
    private void DisableUnwantedExportFormats()
            {
                FieldInfo info;
                foreach (RenderingExtension extension in rptviewerByBrandBySentimentAttribute.ServerReport.ListRenderingExtensions())
                {
                    if (extension.Name != "PDF" && extension.Name != "ASPPT" && extension.Name != "ASPPTX" && extension.Name != "EXCEL" && extension.Name != "MHTML") // only PDF and Excel - remove the other options
                    {
                        info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                        info.SetValue(extension, false);
                    }
                    if (extension.Name == "ASPPT") // change "Excel" name on the list to "Excel 97-2003 Workbook"
                    {
                        info = extension.GetType().GetField("m_localizedName", BindingFlags.Instance | BindingFlags.NonPublic);
                        if (info != null) info.SetValue(extension, "PowerPoint 2003");
                    }
                    if (extension.Name == "ASPPTX") // change "Excel" name on the list to "Excel 97-2003 Workbook"
                    {
                        info = extension.GetType().GetField("m_localizedName", BindingFlags.Instance | BindingFlags.NonPublic);
                        if (info != null) info.SetValue(extension, "PowerPoint 2007");
                    }
                }
            }

    neha
    Friday, November 11, 2011 7:39 AM

All replies

  • Hi,

    Thank you for this article.

    I am using the localreport ReportViewer 2010 and other code examples weren't working.

    Apparently, the m_isVisible field was not available in earlier version of ReportViewer

                        info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);

                        info.SetValue(extension, false);


    Code that wasn't working:

                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);

                        }

                    }

                }

    Thanks again, chupaul :)



    • Edited by chupaul Thursday, April 3, 2014 8:27 PM
    Thursday, April 3, 2014 8:24 PM