Archive

Archive for the ‘ASP.NET’ Category

Hide export format in RDLC/SSRS Report Viewer control

May 10, 2010 8 comments

I recently needed to hide or disable PDF format in Export Formats dropdown list displayed in SSRS ReportViewer’s toolbar in Local Report mode.

Unfortunately, ReportViewer control has no method or property to manage specific format’s visibility and this is true also for the recently released Report Viewer 10.

We can use Report Viewer’s property ShowExportControls to hide the export formats dropdown list but not a specific format such as PDF.

In Local Report mode, there are 2 export formats (Excel and PDF) and more Rendering Extensions for Server Report mode are available.

We have the option to hide export formats control and implement our own list. this article might help on this.

Finally, I ended up with adding new extension method SetExportFormatVisibility to ReportViewer control which uses private Reflection to disable/enable export formats.

This method is inspired by Stephen Songer’s blog post Disable/Enable export format in SSRS and ASP.NET.

The code consists of two parts, one is ReportViewerExtensions class which has SetExportFormatVisibility extension method and the second is ReportViewerExportFormat Enum to specify available export formats.

public static class ReportViewerExtensions
 {
 public static void SetExportFormatVisibility(this ReportViewer viewer, ReportViewerExportFormat format, bool isVisible)
 {

 string formatName = format.ToString();

 const System.Reflection.BindingFlags Flags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance;
 System.Reflection.FieldInfo m_previewService = viewer.LocalReport.GetType().GetField("m_previewService", Flags);

 System.Reflection.MethodInfo ListRenderingExtensions = m_previewService.FieldType.GetMethod("ListRenderingExtensions", Flags);
 object previewServiceInstance = m_previewService.GetValue(viewer.LocalReport);

 IList extensions = (IList)ListRenderingExtensions.Invoke(previewServiceInstance, null);
 System.Reflection.PropertyInfo name = extensions[0].GetType().GetProperty("Name", Flags);

 //object extension = null;
 foreach (var ext in extensions)
 {

 if ((string.Compare(name.GetValue(ext, null).ToString(), formatName, true) == 0))
 {
 System.Reflection.FieldInfo m_isVisible = ext.GetType().GetField("m_isVisible", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

 System.Reflection.FieldInfo m_isExposedExternally = ext.GetType().GetField("m_isExposedExternally", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
 m_isVisible.SetValue(ext, isVisible);
 m_isExposedExternally.SetValue(ext, isVisible);

 break;
 }

 }
 }

 }

 public enum ReportViewerExportFormat
 {
 Excel,
 PDF
 }

Simple to use..

 ReportViewer1.SetExportFormatVisibility(ReportViewerExportFormat.PDF, false); 

Shout it kick it on DotNetKicks.com Retweet

Categories: ASP.NET Tags: , , ,

Visual Studio 2010 Report Designer doesn’t support SSRS 2005 format

April 16, 2010 17 comments

Note: This issue should be resolved by converting VS 2008 (SSRS 2005) RDLCs to VS 2010 (SSRS 2008) RDLCs and adding Microsoft.ReportViewer.WebForms.dll Version 10 reference to your .NET Framework 3.5 project’s references instead of Version 9

Thanks to the Framework Multi-Targeting new feature of Visual Studio 2010 which enables .NET developers to develop .NET applications which target the previous versions of .NET Framework using Visual Studio 2010.

Based on this, I have decided to remove all previous Visual Studio versions and install Visual Studio 2010.

By the way, I have struggled to uninstall Visual Studio 2008. When I used the regular uninstall through Windows Control Panel. I have got a message which says something like “Can’t uninstall Visual Studio 2008″.

After few trials to find what is the wrong with my system, I did a quick search I found that this problem raised due to some Visual Studio 2008 hot fixes and updates which cannot be removed by the normal uninstall process. Therefore Microsoft provides Auto Uninstall Tool to completely remove Visual Studio 2008.

If you run this tool, the below screen will be displayed. just click Yes to start the cleaning process.

Let’s get back to the main reason I did this blog post for. I used Visual Studio 2010 to open ASP.NET application developed using .NET Framework 3.5. I got the below message when I tried to open RDLC report.

This message asks if I want to convert RDLC report format to 2008. After I canceled the conversion, the report designer showed “The version of the report definition language (RDL) is not support by Visual Studio 2010 Report Designer” message as you can see at the following figure

This problem happens due to Visual Studio 2008 Report Designer uses SQL Server Reporting Service (SSRS) 2005 format to work with RDLC reports and Visual Studio 2010 uses SSRS 2008 format.

It supposed that Report Designer 2010 has the ability to open and edit the previous RDLC formats for the sake of back compatibility.

I recalled that after SSRS 2008 was released, developers were not able to create RDLC reports in 2008 format and the reason of that is Visual Studio 2008 released before SQL Server 2008!.

However, I still have the ability to convert the report to RDLC 2008 format which is weird. .NET Framework 3.5 “Microsoft Report Viewer” control doesn’t support RDLC 2008 format in Local mode.

The following figure shows the message you’ll get if you try to run RDLC 2008 report under .NET Framework 3.5.

The question here is: Why I can convert RDLC 2005 to RDLC 2008 whereas I still use .NET Framework 3.5?!

Shout it kick it on DotNetKicks.com Retweet

ASP.NET 4 – Web.config File Minification

March 27, 2010 2 comments

Do you agree that ASP.NET Application’s web.config became very big and hard to read?
ASP.NET Team Development also agreed on that and introduce some enhancements to make web.config content simple and easy to read.

ASP.NET Platform configurations based on two config files, First one is machine.config which contains common configuration data like define available configSections to be used in this version of framework and other global elements such as processModel.
You can find machine.config for framework 2.0,3.0 and 3.5 through C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG. you should notice that all these frameworks working under the CLR v2.0.50727 which means they use the same machine.config

web.config is the second file you need to properly configure your ASP.NET application. web.config should contain only application specific information. because of mentioned-above frameworks upgrade the framework Class Library and introduce new services which working under the same CLR. these new services and libraries should be configured and registered in web.config such as Ajax, routing, and integration with IIS 7.

In Framework 4, we have new CLR and new machine.config, so all common configuration data have been moved to the new machine.config and made web.config simple and clear.

In ASP.NET 4, web.config might be empty or contain very few lines

ASP.NET 4 Web.Config Minification

ASP.NET 4 Web.Config Minification

Shout it

kick it on DotNetKicks.com

Retweet

Categories: ASP.NET Tags: ,
Follow

Get every new post delivered to your Inbox.