Tuesday, 24 December 2013

Example to disable save as certain file type in SSRS Report Viewer

Leave a Comment
SQL Server Reporting Service(SSRS) is a full range of ready-to-use tools and services to help you create, deploy, and manage reports for your organization, as well as programming features that enable you to extend and customize your reporting functionality.

The Report Viewer provide functionality to save the report as a pdf, word and also as a excel format. Sometime organization require this feature, sometime not. This is how to disable save as function in Report Viewer(SSRS).

The example will invoke methode pre-render in Report Viewer Controller.

The ASPX Page

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> 

:

:

: 

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
        InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"
        Height="730px" Width="886px" ShowCredentialPrompts="False" ShowDocumentMapButton="False"
        ShowParameterPrompts="False" ShowWaitControlCancelLink="False" EnableTheming="False"
        ExportContentDisposition="AlwaysAttachment" OnPreRender="ReportViewer1_PreRender">
        <LocalReport ReportPath="Reports\Report1.rdlc">
            <DataSources>
                <rsweb:ReportDataSource DataSourceId="SqlDataSource1" Name="DataSet1" />               
            </DataSources>
        </LocalReport>
    </rsweb:ReportViewer>
  
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:UnitTrustSystemConnectionString %>"
        SelectCommand="SELECT [CREATE_USERID], [REPORT_ID], [SEQ_NO], [V1], [V2], [V3] FROM [T_REPORT_DTL] WHERE ([CREATE_USERID] = @CREATE_USERID)">
        <SelectParameters>
            <asp:QueryStringParameter Name="CREATE_USERID" QueryStringField="uid" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

The Code Behind

        protected void ReportViewer1_PreRender(object sender, EventArgs e)
        {
            DisableUnwantedExportFormat((ReportViewer)sender, "Excel");
            DisableUnwantedExportFormat((ReportViewer)sender, "Word");
        } 



        /// <summary>
        /// Hidden the special SSRS rendering format in ReportViewer control
        /// </summary>
        /// <param name="ReportViewerID">The ID of the relevant ReportViewer control</param>
        /// <param name="strFormatName">Format Name</param>
        public void DisableUnwantedExportFormat(ReportViewer ReportViewerID, string strFormatName)
        {
            FieldInfo info;
            foreach (RenderingExtension extension in ReportViewerID.LocalReport.ListRenderingExtensions())
            {
                if (extension.Name.Trim().ToUpper() == strFormatName.Trim().ToUpper())
                {
                    info = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                    info.SetValue(extension, false);
                }
            }

        }

The Output Before

The Output After


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.