iAlpine.net
A journey of exploration and discovery

Staying on the right path

February 12, 2011 00:41 by mihko


ASP.NET & SSRS - Render report to PDF format

June 2, 2009 11:00 by mihko


Let's say you want to display a report that you made with SQL Reporting server as a PDF document to the users on the Web. With ASP.NET and using SSRS this can be done by calling the method ReportViewer.ServerReport.Render(). The same render method can be used as well to export SSRS reports to Excel and also image TIF formats. 

To create a PDF file directly from your report in SSRS you should add the following lines of code after definition of your report paths and after setting the parameters for the report.


Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string deviceInfo;
deviceInfo =
"<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>";
byte[] bytes = ReportViewer1.ServerReport.Render("PDF", null, out mimeType, out encoding, out extension,out streamids, out warnings);

Response.Buffer =
true;
Response.Clear();
Response.ContentType = mimeType;

// This header is for saving it as an Attachment and popup window should display to to offer save as or open a PDF file 
//Response.AddHeader("Content-Disposition", "attachment; filename=" + extension);

Response.AddHeader("content-disposition", "inline; filename=myfile." + extension);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();


MS SQL Reporting Serices 2005 - Unable to load client print control - Print button error guide

May 22, 2009 13:11 by mihko


In this post I share my experience of how much trouble I had to go through to fix Microsoft print button control on SQL Reporting Services 2005 that suddenly stopped working one beautiful day on most of the client machines.

Please note that in the post I never truly managed to solve the problem completely. I have found a work around to the solution so that at least my clients can normally use printing functionality on the Web reports that were built with SSRS.

The problem with print control "Unable to load client print control" only appeared when trying to print from a Microsoft Web control MicrosoftReportViewer. All my Windows Forms report viewer print controls are working normally. To this I want to add that on my development machine where I have both MS SQL Server & SSRS installed I never had such problems if running application locally. The problem occurred on a production server where I used MicrosoftReportViewer in my application to generate a report. The print button control also seems to work normally if using control directly over SSRS web application at (http://servername/Reports/MyReport).

Although, I checked many posts over the web, most of the resolutions that described that the problem can be resolved by uninstalling MS updates as KB956391, KB960715 or setting different ActiveX settings in IE did not work for me. A few websites that I did find useful and helped me in solving the issue are added under my post.


After I tested the print control on different client machines I found out that the problem is ActiveX Control compatibility and versions of RSCientPrint Class that were installed on the machines and the one that is included in MicrosoftReportViewer.

1. To see which version of RSClinetPrint class you have installed on your machine you can check in IE under Internet Options -> Programs -> Manage Add-ons.

What I found out is that printing worked only with older class installed "RSClinetPrint class" and not with "RSClinetPrint class 2005".  The problem I had with most of the client machines was that only newer version RSClinetPrint class 2005 were installed and they very likely came with new Windows Updates. 

Since installing and deploying the older version of RSClinetPrint class has proven to be extremely painful & problematic. I had to try to make this to work with new version of class. This is where a post of Brian Hartman's on Report Viewer Blog came very useful. 

Alternative 1. Updating sofware as described on Brian's blog SQL Server 2005 Report Viewer 2005 Redistributable and VS 2005 did not fix my problem so my last choice was to include a print control separately as described below.


Here is what I did to make printing control included separately:


Step 1: I made a test.html page with a JavaScript function Print() and included an object RSClientPrint with CLASSID
="CLSID:41861299-EAB2-4DCC-986C-802AE12AC499" which is the classID of new "RSClinetPrint class 2005" and path to CODEBASE="../App_Code/RSClientPrint.cab" where I copied a file RSClientPrint.cab file from -> Program Files -> SQL Server.

<HTML xmlns="http://www.w3.org/1999/xhtml">
<
HEAD></HEAD>        
<BODY onload="Print()">                         
<script language="javascript">       
function Print(){       
if (typeof RSClientPrint.Print == "undefined")       
{        alert("Unable to load client print control.");       
return;       
}        
RSClientPrint.MarginLeft= 10;        
RSClientPrint.MarginTop= 10;        
RSClientPrint.MarginRight= 10;        
RSClientPrint.MarginBottom= 10;        
RSClientPrint.PageHeight= 297;        
RSClientPrint.PageWidth= 210;        
RSClientPrint.Culture= 1033;        
RSClientPrint.UICulture= 9;        
RSClientPrint.UseEmfPlus= true;              
RSClientPrint.Print("http://localhost/reportserver","/Reports/FinancialReport&Year=2008", "Financial")        
}             
</script>       

<OBJECT ID="RSClientPrint" CLASSID="CLSID:41861299-EAB2-4DCC-986C-802AE12AC499" CODEBASE="../App_Code/RSClientPrint.cab"></OBJECT>

</BODY> 
</HTML>


Step 2: After I uploaded the test.html page to the server the print control did work on some client machines but still not on all of them. My diagnostics after checking in IE which version of RSClentPrint control is installed was that the control did not work on machines where there was an older version of RSClientPrint control installed.

Step 3: On client machine I removed the ActiveX control from C:\Windows\Downloaded Program Files by deleting all files.

Step 4: I also checked if in IE in Internet Options - > Security – Local Internet -> Custom Level option -> "Allow previously unused ActiveX controls to run without prompt" is set as Disabled so that a new window will pop up to try to install a new ActiveX control. 

Step 5: Another option that I have enabled on the machine in IE was Enable ActiveX controls.

Step 6: On most of the client machines that did the trick however on a few I still got an error “Error loading resource library. (0x8007007E)”. To solve this problem first I tried a solution from the web to unregister and register rsclientprint.dll with CMD command: Regsvr32 rsclientprint.dll /u and Regsvr32 rsclientprint.dll which did not work.

Step 7: I tried another solution that recommended to copy all RSClinetPrint rll files from RSClientPrint.cab file to  C:\Windows\Dowlnoaded Program Files. Note that you cannot do it with copy and paste and you will need to go to command prompt and use xcopy command. 

Step 8: I tested my page test.html and print button worked normally on the problematic machines.



USEFUL LINK REFERENCES:

http://dotnetgurus.net/post/2008/10/22/Reportviewer-Print-Problem-After-KB956391-(ActiveX-Kill-Bits-Update).aspx
http://blogs.msdn.com/brianhartman/archive/2008/11/05/client-print-fails-to-load-after-microsoft-update-956391.aspx
http://www.kodyaz.com/articles/client-side-printing-silent-deployment-of-rsclientPrint.aspx
http://social.msdn.microsoft.com/forums/en-US/sqlreportingservices/thread/792cc550-304d-4326-a0a5-0dd430092f7f/


Define custom encodings and cultures in your ASP.NET Website project

March 10, 2009 21:35 by mihko

There might me time when you would want to setup a specific encoding and culture globalization settings to your ASP.NET project. Since Web.config file is the right place to configure most of the settings you can just add in configuration the setting like in the following example:

<configuration>
   <system.web>
      <globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="de-DE"
        />
   </system.web>
</configuration>

To check all Culture Info classes a good website is:

http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(VS.71).aspx


ASP.NET Hide GridView Column to user without losing its value

July 29, 2008 12:18 by mihko

This trick might save you some time when you want to hide GridView coulmn and keep its column value. By default if you set the attribute visible="false" like in example below you will also lose data of that column. Apperenlty the whole column and its value is removed in GridView.

Example 1:

<asp:BoundField Visible="false" DataField="Odobren" HeaderText="Odobren" SortExpression="Odobren" />


My workaround is that you set in your style class to hide your column and then use it in your code to hide your column from the users.

Example 2:

.gridViewHiddenColumn

{
display:none;
}

<asp:BoundField DataField="Odobren" HeaderText="Odobren" HeaderStyle-CssClass="gridViewHiddenColumn" itemstyle-cssclass="gridViewHiddenColumn" SortExpression="Odobren" />

Example 3:

If you want to do in you code behind, you can call an event GridView_RowCreated and set visibility of the row to false.

e.Row.Cells[13].Visible = false;

 





  

Sponsors


www.knetit.net

Kiva - loans that change lives


  

Job Board for Web Designers and Web Developers

The On Demand Global Workforce - oDesk

affiliate_link