locked
How to allow Export to Excel only in RDLC ?? (NO Word/PDF) RRS feed

  • Question

  • User-1042970710 posted

    Hi Friends,

    I want my RDLC report report to Allow export  only Excel Reports. I  found this code on internet.    Unfortunately. It hides only  PDF  not the WORD   can anyone help me?

     <asp:Panel ID="pnlReport" runat="server" Visible="false" >
                           <rsweb:ReportViewer  Font-Names="DIN Next LT Arabic Light" ID="EventsReportByPeriod" runat="server"  Height="1190px" Width="100%" Visible="true" onload="ReportViewer_OnLoad" ShowPrintButton="False" ShowPromptAreaButton="False" ZoomMode="FullPage" ></rsweb:ReportViewer>
                     </asp:Panel>
     protected void ReportViewer_OnLoad(object sender, EventArgs e)
            {
    
    
                string[] exportOption = new string[] { "Word", "PDF" };
    
    
                foreach (var item in exportOption)
                {
                    RenderingExtension extension = EventsReportByPeriod.LocalReport.ListRenderingExtensions().ToList().Find(x => x.Name.Equals(item, StringComparison.CurrentCultureIgnoreCase));
                    if (extension != null)
                    {
                        System.Reflection.FieldInfo fieldInfo = extension.GetType().GetField("m_isVisible", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                        fieldInfo.SetValue(extension, false);
                    }
                }
            }

      

    Monday, December 10, 2018 9:04 AM

Answers

  • User283571144 posted

    Hi jalali

    According to your description , I have made a sample here.You can achieve your requirement by editing  OnPreRender Event .Here is the code ,I hope it will help you.

    Test.aspx:

    <head runat="server">
        <title></title>
    
       
    </head>
    <body>
         
        <form id="form1" runat="server">
            <asp:Panel ID="pnlReport" runat="server"  >
                 <asp:ScriptManager runat="server"></asp:ScriptManager>         
                           <rsweb:ReportViewer Font-Names="DIN Next LT Arabic Light" ID="EventsReportByPeriod" runat="server"  Height="1190px" Width="100%" OnPreRender="EventsReportByPeriod_PreRender" ShowPrintButton="False" ShowPromptAreaButton="False" InteractivityPostBackMode="AlwaysSynchronous"  ZoomMode="FullPage" BackColor="" ClientIDMode="AutoID" HighlightBackgroundColor="" InternalBorderColor="204, 204, 204" InternalBorderStyle="Solid" InternalBorderWidth="1px" LinkActiveColor="" LinkActiveHoverColor="" LinkDisabledColor="" PrimaryButtonBackgroundColor="" PrimaryButtonForegroundColor="" PrimaryButtonHoverBackgroundColor="" PrimaryButtonHoverForegroundColor="" SecondaryButtonBackgroundColor="" SecondaryButtonForegroundColor="" SecondaryButtonHoverBackgroundColor="" SecondaryButtonHoverForegroundColor="" SplitterBackColor="" ToolbarDividerColor="" ToolbarForegroundColor="" ToolbarForegroundDisabledColor="" ToolbarHoverBackgroundColor="" ToolbarHoverForegroundColor="" ToolBarItemBorderColor="" ToolBarItemBorderStyle="Solid" ToolBarItemBorderWidth="1px" ToolBarItemHoverBackColor="" ToolBarItemPressedBorderColor="51, 102, 153" ToolBarItemPressedBorderStyle="Solid" ToolBarItemPressedBorderWidth="1px" ToolBarItemPressedHoverBackColor="153, 187, 226" >
                               
                               <LocalReport ReportPath="Report1.rdlc">
                                   <DataSources>
                                       <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
                                   </DataSources>
                               </LocalReport>
                               
                           </rsweb:ReportViewer>
                         
                     <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="Demo.MyDatabase2DataSetTableAdapters.CityTableAdapter"></asp:ObjectDataSource>
                         
               
                     </asp:Panel>
    
         
        </form>
    </body>
    

    Code-behind:

    public partial class WebForm7 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
          
    
            protected void EventsReportByPeriod_PreRender(object sender, EventArgs e)
            {
      foreach (RenderingExtension extension in EventsReportByPeriod.LocalReport.ListRenderingExtensions())
                {
                    if (extension.Name == "IMAGE" || extension.Name == "WORDOPENXML" || extension.Name == "PDF")
                    {
                        FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                        fi.SetValue(extension, false);
                    }
                }
    
            }
        }
     
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 11, 2018 5:20 AM

All replies

  • User283571144 posted

    Hi jalali

    According to your description , I have made a sample here.You can achieve your requirement by editing  OnPreRender Event .Here is the code ,I hope it will help you.

    Test.aspx:

    <head runat="server">
        <title></title>
    
       
    </head>
    <body>
         
        <form id="form1" runat="server">
            <asp:Panel ID="pnlReport" runat="server"  >
                 <asp:ScriptManager runat="server"></asp:ScriptManager>         
                           <rsweb:ReportViewer Font-Names="DIN Next LT Arabic Light" ID="EventsReportByPeriod" runat="server"  Height="1190px" Width="100%" OnPreRender="EventsReportByPeriod_PreRender" ShowPrintButton="False" ShowPromptAreaButton="False" InteractivityPostBackMode="AlwaysSynchronous"  ZoomMode="FullPage" BackColor="" ClientIDMode="AutoID" HighlightBackgroundColor="" InternalBorderColor="204, 204, 204" InternalBorderStyle="Solid" InternalBorderWidth="1px" LinkActiveColor="" LinkActiveHoverColor="" LinkDisabledColor="" PrimaryButtonBackgroundColor="" PrimaryButtonForegroundColor="" PrimaryButtonHoverBackgroundColor="" PrimaryButtonHoverForegroundColor="" SecondaryButtonBackgroundColor="" SecondaryButtonForegroundColor="" SecondaryButtonHoverBackgroundColor="" SecondaryButtonHoverForegroundColor="" SplitterBackColor="" ToolbarDividerColor="" ToolbarForegroundColor="" ToolbarForegroundDisabledColor="" ToolbarHoverBackgroundColor="" ToolbarHoverForegroundColor="" ToolBarItemBorderColor="" ToolBarItemBorderStyle="Solid" ToolBarItemBorderWidth="1px" ToolBarItemHoverBackColor="" ToolBarItemPressedBorderColor="51, 102, 153" ToolBarItemPressedBorderStyle="Solid" ToolBarItemPressedBorderWidth="1px" ToolBarItemPressedHoverBackColor="153, 187, 226" >
                               
                               <LocalReport ReportPath="Report1.rdlc">
                                   <DataSources>
                                       <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
                                   </DataSources>
                               </LocalReport>
                               
                           </rsweb:ReportViewer>
                         
                     <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="Demo.MyDatabase2DataSetTableAdapters.CityTableAdapter"></asp:ObjectDataSource>
                         
               
                     </asp:Panel>
    
         
        </form>
    </body>
    

    Code-behind:

    public partial class WebForm7 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
          
    
            protected void EventsReportByPeriod_PreRender(object sender, EventArgs e)
            {
      foreach (RenderingExtension extension in EventsReportByPeriod.LocalReport.ListRenderingExtensions())
                {
                    if (extension.Name == "IMAGE" || extension.Name == "WORDOPENXML" || extension.Name == "PDF")
                    {
                        FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                        fi.SetValue(extension, false);
                    }
                }
    
            }
        }
     
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 11, 2018 5:20 AM
  • User-1042970710 posted

    Work like a charm!!  Thanks!!

    Tuesday, December 11, 2018 1:24 PM