views:

2925

answers:

4

Hi, I make use of a ReportView component in a VB.Net 2005 app. How can I disable the PDF export functionality, only keeping the MS Excel format?

+1  A: 

I managed to disable the PDF Export button with some tinkering. The ReportViewer class does not have any public facing functions to disable the Export to PDF toolbar button. In order to do it, take a look at the following code:

Call this function during the OnLoad event of your reportViewer page:

 Private Sub CustomizeRV(ByVal ctrl As Control)
    For Each c As Control In ctrl.Controls
      If TypeOf c Is ToolStrip Then
        Dim ts As ToolStrip = DirectCast(c, ToolStrip)
        For i As Integer = 0 To ts.Items.Count - 1
          If ts.Items(i).Name = "export" Then
            Dim exp As ToolStripDropDownButton = ts.Items(i)
            AddHandler exp.DropDownOpening, AddressOf disableButton
          End If
        Next
      End If
      If c.HasChildren Then
        CustomizeRV(c)
      End If
    Next
  End Sub

I couldn't set the Visible property of the toolstrip button here, since the Export options are loaded OnDropDownOpened. Instead, I added a handler to take care of disabling the export option when the toolstrip Dropdown is clicked. The handler function is as follows:

  Private Sub disableButton(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim btn As ToolStripDropDownButton = DirectCast(sender, ToolStripDropDownButton)
    btn.DropDownItems(1).Visible = False
  End Sub

So basically, Onload you are adding an Event Handler so that when the Export Drop Down button is clicked, the above function will run - making the Export to PDF invisible.

The solution will work for sure, I just finished making it work.

If you have any questions, let me know.

Jon
+2  A: 

This is how you disable a export option, just mark all the ones except Excel to false.
*Don't forget to restart the Reporting Services service.

File: InstallPath\Reporting Services\ReportServer\rsreportserver.config

Enabled:

<Extension Name="EXCEL"
Type="Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer,Microsoft.ReportingServices.ExcelRendering"/>

Disabled:

<Extension Name="EXCEL"
Type="Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer,Microsoft.ReportingServices.ExcelRendering"
Visible="false"/>
rick schott
+2  A: 

Using the jon's code above as a reference, I manage to hide "Excel" in the program at runtime. However, I am not good a VB.net so I put a sample in C#. Sorry about that but I hope this helps. One more thing, the report the embedded inside an ASP.net page.

  // This is the Load event of the reports itself.
  // Call the recursive method.
  protected void ReportViewerResults_Load(object sender, EventArgs e)
  {
    CustomizeRV((System.Web.UI.Control)sender);
  }

  // Patterned from Jon.
  // Traverse all controls/child controls to get the dropdownlist.
  // The first dropdown list is the ZoomGroup, followed by the ExportGroup.
  // We just wanted the ExportGroup.
  // When a dropdownlist is found, create a event handler to be used upon rendering.
  private void CustomizeRV(System.Web.UI.Control reportControl)
  {
    foreach (System.Web.UI.Control childControl in reportControl.Controls)
    {
      if (childControl.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
      {
        System.Web.UI.WebControls.DropDownList ddList = (System.Web.UI.WebControls.DropDownList)childControl;
        ddList.PreRender += new EventHandler(ddList_PreRender);
      }
      if (childControl.Controls.Count > 0)
      {
        CustomizeRV(childControl);
      }
    }
  }

  // This is the event handler added from CustomizeRV
  // We just check the object type to get what we needed.
  // Once the dropdownlist is found, we check if it is for the ExportGroup.
  // Meaning, the "Excel" text should exists.
  // Then, just traverse the list and disable the "Excel".
  // When the report is shown, "Excel" will no longer be on the list.
  // You can also do this to "PDF" or if you want to change the text.
  void ddList_PreRender(object sender, EventArgs e)
  {
    if (sender.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
    {
      System.Web.UI.WebControls.DropDownList ddList = (System.Web.UI.WebControls.DropDownList)sender;
      System.Web.UI.WebControls.ListItemCollection listItems = ddList.Items;

      if ((listItems != null) && (listItems.Count > 0) && (listItems.FindByText("Excel") != null))
      {
        foreach (System.Web.UI.WebControls.ListItem list in listItems)
        {
          if (list.Text.Equals("Excel")) 
          {
            list.Enabled = false;
          }
        }
      }
    }
  }

I was trying to select the default item to "PDF" but could not find a way to enable the "Export" text button. :-(

marlon
A: 

You can also check my post on how to make Excel the first option in the dropdown:

SSRS-Making Excel the default export option

aackose