Disable Export Options Per Report in SSRS 2012/ 2014

August 3, 2016

If we want to disable export options for all reports in SQL Server Reporting Services (SSRS) 2012/ 2014, then we would set the parameters in the RSReportServer.config file on the Reporting Server.  However, most of the time, you are going to want to be able to export at least a few reports, so how do we disable exports for only a few reports?  And what if we want to only disable some of the export options?

 

There is not an easy out of the box way to do this.  However, with a little JavaScript and the magic of the DOM, you can adjust the resulting report page to hide the objects that you do not want displayed (in our case some of the export options).  

 

All you need to do is add the Javascript below to your Report.aspx page.  Note that by default the page only has two lines in the file, so I have added the contents of my entire Reports.aspx page below:

 

<%@ Register TagPrefix="MSRS" Namespace="Microsoft.ReportingServices.UI" Assembly="ReportingServicesWebUserInterface" %>

<%@ Page language="c#" Codebehind="Report.aspx.cs" AutoEventWireup="false" Inherits="Microsoft.ReportingServices.UI.ReportWrapperPage" EnableEventValidation="false" %>

 

<script language = "Javascript">

 

// Disable Export Options Per Report

//

// This JavaScript is used to disable export options in reports.  In order to disable an option add another call to RemoveExportOptions

//

// Example:  RemoveExportOption("/ReportProject1/Report1", "Excel");

//

// In order to implement this, just save the script in the Report.apsx page of the SSRS server.  No reboot or restart is needed.  It will just work :)

//

 

var timer;

var dueTime=0

 

var options =   {           

                                         "excel":"Excel",

                                         "xml":"XML file with report data",

                                         "csv":"CSV (comma delimited)",

                                         "pdf":"PDF",

                                         "mhtml":"MHTML (web archive)",

                                         "tiff":"TIFF file",

                                         "word":"Word"

                           }  

 

function RemoveCTLExportFormats(format)

{             

                dueTime += 50;

                if(dueTime > 30000)

                {

                                clearTimeout(timer);

                                return;

                }

                

                           if (format.toLowerCase() == "all")

                           {                         

                                         var obj=document.getElementsByTagName("table");

                             for(var i=0;i<obj.length;i++)

                           {

                                if (obj[i].title == "Export drop down menu")

                                {

                                                                     obj[i].style.display="None"                             

                                                                                                                                

                                }

                           }

                           }

                           else

                           {

                                         var obj=document.getElementsByTagName("A");

                           for(var i=0;i<obj.length;i++)

                           {

                                  if (obj[i].title == options[format])

                                        {

                                                                                   obj[i].style.display="None"                             

                                                                                                                                

                                                      }

                           }

                           }

                timer=setTimeout("RemoveCTLExportFormats('" + format + "')",50);               

}

 

 

function RemoveExportOption(report, format)

{

              url = unescape(location.href).replace("&","").replace("+","")

 

              if (url.indexOf(report) != -1)

              {

                timer2=setTimeout("RemoveCTLExportFormats('" + format.toLowerCase() + "')",50);

        }

        else

        {

                return;

        }

}

 

 

// List the reports with the options you want removed.  Leave special characters and spaces out of the report path:

//

// Example: /My New Report/Report Test 1  => /MyNewReport/ReportTest1 

//

// If you want to remove multiple options, then list the report multiple times.  "ALL" removes all the export options

//

// Options are (not case sensitive):

//

// ALL - Removes all the options

// Excel - Removes Excel

// XML - Removes XML file with report data

// CSV - Removes CSV (comma delimited)

// PDF - Removes PDF

// MHTML - Removes MHTML (web archive)

// TIFF - Removes TIFF file

// Word - Removes Word

// 

 

RemoveExportOption("/ReportProject1/Report1", "Excel");

// RemoveExportOption("/ReportProject1/Report1", "csv");

// RemoveExportOption("/ReportProject1/Report1", "pdF");

// RemoveExportOption("/ReportProject1/Report1", "mhtml");

// RemoveExportOption("/ReportProject1/Report1", "TiFf");

// RemoveExportOption("/ReportProject1/Report1", "word");

// RemoveExportOption("/ReportProject1/Report1", "AlL");

 

</script>

 

Hopefully that helps you out and that I've added enough comments to explain how to use it.

 

Special thanks to Jinchun who first solved the puzzle for SQL 2005/2008 which I used as a base for the solution above.  Below is the URL to his post.  

 

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/0c680c69-9f7d-42aa-a6b4-b1178eab8adf/limit-report-from-being-exported-to-excel?forum=sqlreportingservices

 

 

 

Please reload

Featured Posts

Cleverspeck Joins the Microsoft Enterprise Cloud Alliance

July 14, 2016

1/2
Please reload

Recent Posts
Please reload

Archive
Please reload

Search By Tags
Please reload

Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square

© 2016 Cleverspeck, LLC. All rights reserved.