Saturday, 28 November 2009
Bug in MS Reporting
Not sure it is a feature because it looks too buggy. In case of using hiding rule for a table element, Interactive Height rule does not work for that report. At a first glance it is not a big problem, but if the report must be built on a huge dataset, it takes too much time to render huge HTML, transfer it to a client and render it in a browser. In my case a report built on ~1 000 000 records was displayed at client in about 10 minutes in IE. After the hiding rule was removed the report was displayed in a few seconds.
Tuesday, 24 November 2009
Advanced export
Customer of the project, which I am working on, asked us to make additional functionality for our reporting tool: exported Microsoft Report should look different when previewed report.
There are different methods to implement such behaviour. One of them is a Rendering Extension but Microsoft says it is better to change the report instead of implementing Rendering Extension. Partially I checked this solution but was not satisfied. Adding the buttons over Report Viewer control is not the case because UI is already approved by the customer and there is no possibility to make any changes.
Finally found and implemented solution looks like this:
1. implement new rdl report which should look like customer wants to export;
2. add the next element on a page where ReportViewer control is placed
<iframe id="reportDownloader" src="../blank.html" width="10" height="10" style="display:none;"></iframe>
3. the next javascript code helps us to handle client export click
function HandleClientSideExportAlt()
{
var formatDropDown = GetControl(this.m_formatsID);
if (formatDropDown.selectedIndex == 0) return false;
var selectedFormat = formatDropDown.value;
var fullExportUrl = "/AdvancedExport.aspx?exportFormat=" + escape(selectedFormat);
document.getElementById('reportDownloader').src = fullExportUrl;
formatDropDown.selectedIndex = 0;
this.m_exportController.SetViewerLinkActive(false);
return true;
}
RSToolbar.prototype.HandleClientSideExport = HandleClientSideExportAlt;
4. in Page_Load method of AdvancedExport.aspx implement your Server Report export:
String ExportFormat = String.IsNullOrEmpty(Request["exportFormat"]) ? "EXCEL" : Request["exportFormat"].ToUpper();
String exportFileName = String.Format("Report{0}.{1}",
DateTime.Now.ToString("ddMMyyhhmmss"),
ExportFormat.Contains("EXCEL") ? "xls" : "pdf");
using (ReportViewer rv = new ReportViewer())
{
ServerReport serverReport = rv.ServerReport;
serverReport.ReportServerUrl = ...
serverReport.ReportPath = ... <- name of new report from step 1.
serverReport.SetParameters(...);
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = serverReport.Render(ExportFormat, null, out mimeType, out encoding, out extension, out streamids, out warnings);
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-length", bytes.Length.ToString());
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", exportFileName));
Response.BinaryWrite(bytes);
}
Excel and PDF formats are just examples and current solution can be used for other exporting formats.
There are different methods to implement such behaviour. One of them is a Rendering Extension but Microsoft says it is better to change the report instead of implementing Rendering Extension. Partially I checked this solution but was not satisfied. Adding the buttons over Report Viewer control is not the case because UI is already approved by the customer and there is no possibility to make any changes.
Finally found and implemented solution looks like this:
1. implement new rdl report which should look like customer wants to export;
2. add the next element on a page where ReportViewer control is placed
<iframe id="reportDownloader" src="../blank.html" width="10" height="10" style="display:none;"></iframe>
3. the next javascript code helps us to handle client export click
function HandleClientSideExportAlt()
{
var formatDropDown = GetControl(this.m_formatsID);
if (formatDropDown.selectedIndex == 0) return false;
var selectedFormat = formatDropDown.value;
var fullExportUrl = "/AdvancedExport.aspx?exportFormat=" + escape(selectedFormat);
document.getElementById('reportDownloader').src = fullExportUrl;
formatDropDown.selectedIndex = 0;
this.m_exportController.SetViewerLinkActive(false);
return true;
}
RSToolbar.prototype.HandleClientSideExport = HandleClientSideExportAlt;
4. in Page_Load method of AdvancedExport.aspx implement your Server Report export:
String ExportFormat = String.IsNullOrEmpty(Request["exportFormat"]) ? "EXCEL" : Request["exportFormat"].ToUpper();
String exportFileName = String.Format("Report{0}.{1}",
DateTime.Now.ToString("ddMMyyhhmmss"),
ExportFormat.Contains("EXCEL") ? "xls" : "pdf");
using (ReportViewer rv = new ReportViewer())
{
ServerReport serverReport = rv.ServerReport;
serverReport.ReportServerUrl = ...
serverReport.ReportPath = ... <- name of new report from step 1.
serverReport.SetParameters(...);
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = serverReport.Render(ExportFormat, null, out mimeType, out encoding, out extension, out streamids, out warnings);
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-length", bytes.Length.ToString());
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", exportFileName));
Response.BinaryWrite(bytes);
}
Excel and PDF formats are just examples and current solution can be used for other exporting formats.
Thursday, 19 November 2009
While you are away...
Couple of days ago I wrote one tool which should check if computer was locked and I found a very simple solution. It was enough to handle SessionSwitch event of SystemEvents class from Microsoft.Win32 namespace.
SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
...
void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLock:
//computer locked
case SessionSwitchReason.SessionUnlock:
//computer unlocked
}
}
It can be used in a wide variety of cases, as an example you can start downloading an update or something else or maybe start some calculations and so on.
SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
...
void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLock:
//computer locked
case SessionSwitchReason.SessionUnlock:
//computer unlocked
}
}
It can be used in a wide variety of cases, as an example you can start downloading an update or something else or maybe start some calculations and so on.
Tuesday, 10 November 2009
Here I am
Hi there! I decided to start writing my personal blog in English. I have had no language practice since my last project for a foreign customer was over. I suppose this blog will improve my written English skills. Sure, it is not a spoken practice, which is much more needed in real life, but it will extend my personal vocabulary. I hope to have enough time to translate and repost here ideas from my Russian blog which is still alive at http://anotheronestory.blogspot.com/
Subscribe to:
Comments (Atom)

