SharePoint 2007 list item print button with SSRS reportviewer

Recently I was tasked to migrate the old Asset data on Access db to SharePoint 2007. It's not difficult using 'Export to Sharepoint List' command and modified certain things such as creating new asset content type, site columns etc.

I can view the list and the items. Great. but there is no print button! In Access db, they were using Access form to print the asset item. In SharePoint 2007, turns out that I have to do a bit of development to do just that.

I found the nice blog on how to do this. However, I don't want to spend ridiculous amount of time playing with HTML markup to get the design I want. It is error-prone as well in terms of printing etc.

Therefore, I decided to try using Reporting Service reportviewer control on the page that will render the layout. The list item details will be passed as parameters :) Cool!

If you search google, you would find many articles about passing the parameters in the URL. this is not good since you will get ugly url and it will give you limitation in size. By exposing the 'custom action' into a list 'content type', we can get the List and ID to work with (mentioned in the above blog).

Enough of the theory, let's see how we can get this going:
1. Design the SSRS report (uh-huh). Add the parameters for each of the list item column you want to include.


2. Upload it to your report server. Then your report is ready for our printing page to consume :)


3.If you follow the blog to add a print button, you should have the button in your list dispform.aspx now! Except that inside the body tag of the print.aspx, we use the reportviewer control :



4. On your code behind (or inside a script tag if you don't want any code behind), get the report from the server and pass the parameters into the Report in the load event:



5. Notice that you need to provide ReportServerCredentials and set the ProcessingMode to Remote. This will ensure that you don't get the nasty 401 Unauthorized Error. The ReportServerCredentials class is listed below:



6. Also don't forget to check if your ReportViewer handlers exist in your web.config:



7. When you successfully deploy your feature, the print button now will take you to the print.aspx and the page will display your report like this:





I hope this article will help you someday :)

Comments

Popular posts from this blog

SharePoint 2013 anonymous access add attachments to list item

Sitecore custom publish agent from specific node and at a specific time

CRM Plugin - Parent and Child Pipeline