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 :)

.NET Convert Word Document into PDF


I came across this old code of converting Word into PDF:

This used to work well until recently the avdoc object sometimes doesn't get the instance (i.e. null) , however running it twice usually fixed it.

I don't know what caused this. It might be a system update or something. I also researched that the above code shouldn't even work since it's using Acrobat interop to open a 'doc' type - so that code was kind of a hack.

To fix the issue, I decided to find alternative way of converting word to PDF pro grammatically. This other way requires office 12 interop instead. So the idea is to open the doc in office and save it as PDF. Simple enough! here is the code:

P.S: Don't forget to install Office2007 and Acrobat on the machine :) enjoy!