Tuesday, December 23, 2014

How to disable the unwanted SSRS report export formats using asp.net c#

How to disable the unwanted SSRS report export formats using asp.net c#

/// <summary>
        /// Disable Unwanted Export Formats
        /// </summary>
        public void DisableUnwantedExportFormats()
        {
            FieldInfo info;
            foreach (RenderingExtension extension in this.rptname.ServerReport.ListRenderingExtensions())
            {
                if (extension.Name == "EXCEL" || extension.Name == "PDF" || extension.Name == "WORD")
                {
                    //info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                    //if (info != null)
                    //{
                    //    Extension rsExtension = info.GetValue(extension) as Extension;
                    //    if (rsExtension != null)
                    //    {
                    //        rsExtension.Visible = false;
                    //    }
                    //}
                    info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                    info.SetValue(extension, true);
                }
                else
                {
                    info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                    info.SetValue(extension, false);
                }
            }
        }

Call this method in page load method
protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
               

                if (!IsPostBack)
                {
                   
                }
                this.DisableUnwantedExportFormats();

            }
            catch (Exception ex)
            {

            }
        }


No comments:

Post a Comment