Integration with Microsoft Report Viewer in local mode

Adding a Reference to Aspose.PDF.ReportingServices.dll to your project.

todo:image_alt_text

C#

 using System.Collections;

using System.Reflection;

using Microsoft.ReportingServices.ReportRendering;

// Use one of the two namespaces below depending on whether you are developing

// a WinForms or WebForms application.

using Microsoft.Reporting.WinForms;

// -- or --

// using Microsoft.Reporting.WebForms;


/// <summary>

/// Adds the specified rendering extension to the specified ReportViewer instance.

/// </summary>

/// <param name="viewer">A ReportViewer control instance.</param>

/// <param name="name">The name of the export format.</param>

/// <param name="localizedName">The localized name of the export format that appears on the dropdown list.</param>

/// <param name="extensionType">The class of the rendering extension to add.</param>

private static void AddExtension(ReportViewer viewer, string name, string localizedName, Type extensionType)

{

    const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;

    // CommonService.ListRenderingExtension is an internal method that returns a list of supported

    // rendering extensions. This list is also stored in a class field so we can simply get this list

    // and add Aspose.PDF for Reporting Services rendering extensions to make Pdf export formats

    // appear on the dropdown.

    // Get the service type.

    FieldInfo previewService = viewer.LocalReport.GetType().GetField("m_previewService", flags);

    // Get the ListRenderingExtensions method info.

    MethodInfo listRenderingExtensions = previewService.FieldType.GetMethod("ListRenderingExtensions", flags);

    // Obtan a list of existing rendering extensions.

    IList extensions = listRenderingExtensions.Invoke(previewService.GetValue(viewer.LocalReport), null) as IList;

    // LocalRenderingExtensionInfo is a class that holds information about a rendering extension.

    // We should create an instance of this class to add the info about the specified extension.

    // Since the IRenderingExtension interface is defined in the Microsoft.ReportViewer.Common

    // assembly, use this trick to obtain the corresponding Assembly instance. This will work for

    // both Report Viewer 2005 (8.0) and 2008 (9.0).

    Assembly commonAssembly = typeof(IRenderingExtension).Assembly;

    // Now, get the LocalRenderingExtensionInfo type as it is defined in the same assembly.

    Type localRenderingExtensionInfoType = commonAssembly.GetType("Microsoft.Reporting.LocalRenderingExtensionInfo");

    // Get the LocalRenderingExtensionInfo constructor info.

    ConstructorInfo ctor = localRenderingExtensionInfoType.GetConstructor(

        flags,

        null,

        new Type[] { typeof(string), typeof(string), typeof(bool), typeof(Type), typeof(bool) },

        null);

    // Create an instance of LocalRenderingExtensionInfo.

    object instance = ctor.Invoke(new object[] { name, localizedName, true, extensionType, true });

    // Finally, add the info about our rendering extension to the list.

    extensions.Add(instance);

}

To add Aspose.Pdf for Reporting Services export format to Microsoft Report Viewer in local mode, use the following code:

C#

 AddExtension(reportViewer1, "APPDF", "PDF via Aspose.PDF",

typeof(Aspose.PDF.ReportingServices.Renderer));
New export format appear in Report Viewer running in local mode.

todo:image_alt_text