IE automation and SQL reporting services c#

1k views Asked by At

I'm working on a project for work that has me running a SQL reporting services report all day long. I would like to automate this process and have gotten pretty far in the process. I can navigate to the page, search for what I want, select the output of the file and click export. The problem I run into is the File Download dialog box that pops regardless of file type or mime settings. I am able to get around it now by using an AutoIt function but its flaky at best. I really want to just download the file to a specific location. My question.. Is there a way to intercept whatever clicking the export button does and get some sort of link to the file? Or is there a way to run the function that link does in asp programmaticly and grabbing the file that way? (Sorry if terminology is off not real familiar with ASP).

Edit... I know there are better ways of doing this with reporting services such as subscriptions etc (thanks for the responses btw :)... But this is what I'm stuck with until I can get the admin to fix a few things. In the company I'm at that involves getting about 20 different departments involved and it will most likely not get fixed. But ultimately my question is whether it is possible to do what im asking in C#. Can I intercept where the code is sending me when I click export and grab the file? Is that even possible?

4

There are 4 answers

0
Degan On

It sounds as if you need to treat the reporting service as if it is completely external. Perhaps WinBatch would help you script interaction with the windows? http://www.windowware.com/

0
user33675 On

Check if you can use URL Access directly against the Reporting Services server: http://msdn.microsoft.com/en-us/library/ms153586.aspx.

If you can modify the web application, try changing the value of ReportViewer.ExportContentDisposition (http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.reportviewer.exportcontentdisposition.aspx) to "AlwaysInline". Alternatively, you can use the Render method (http://msdn.microsoft.com/en-us/library/ms252199.aspx) of ReportViewer.ServerReport or ReportViewer.LocalReport to render into a Response OutputStream.

Otherwise, you need to peek into the JavaScript in the ReportViewer's IFRAME using IE Developer Tools (F12 in IE8). It needs to perform an additional callback to the server to have it render the report in the selected format. Adapt the actions this script performs.

1
Wyatt Barnett On

How much access do you have to SSRS? If you can get pretty much carte blanche, you could setup SSRS to export the report at intervals to a specific location. If SSRS can't hit that location, you could set up SSRS to email the report--from there it is an easy jump to making email dump to location. Either way, there are better angles than "auto click OK" screen-scraping UI automation.


I'd look into the web services. If they can't get scheduling right, they probably didn't get around to turning those off either. Setup a command line app to suck the reports off the services and life will be grand.

2
Chris Latta On

Why not just use the report scheduling feature to automate it? You can enter subscriptions for the report and it can be delivered on a schedule. There are two delivery methods with SSRS out of the box - email and file share. You can even write your own custom delivery extension.