diff --git a/README.md b/README.md index 90d6aee..57a5ad7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,55 @@ # ReportViewer for MVC + ReportViewer for MVC is a simple library that makes it possible to use an ASP.NET ReportViewer control in an ASP.NET MVC application. + It provides a set of HTML Helpers and all of it's dependencies for displaying a report. Local or server, it handles all. + ## Why do I need this? + Server controls (like ReportViewer) cannot be used within Razor views. In order to use a control, you would need to add an ASPX view page and all of it's configurations, as well as, work through the code. + This library will setup all of that work for you, and will provide easy access to display your report. Also, it will auto-resize the report on your webpage to get the desired display. + +## Where can I get it? + +Download & install from [NuGet](https://www.nuget.org/packages/ReportViewerForMvc/). + +```PowerShell +PM> Install-Package ReportViewerForMvc +``` + +## How do I use it? + +After installing, the simplest solution is to setup the report on the controller and render it on the view. + +The example below, will configure a report on localhost and auto-resize it. Check more details on the [Getting Started](https://github.com/armanio123/ReportViewerForMvc/wiki/Getting-Started) page. + +Controller: + +```C# +var reportViewer = new ReportViewer() +{ + ProcessingMode = ProcessingMode.Remote, + SizeToReportContent = true, + Width = Unit.Percentage(100), + Height = Unit.Percentage(100), +}; + +reportViewer.ServerReport.ReportPath = "/ReportFolder/SampleReport"; +reportViewer.ServerReport.ReportServerUrl = new Uri("http://localhost/ReportServer/"); + +ViewBag.DynamicID = Guid.NewGuid().ToString(); +ViewBag.ReportViewer = reportViewer; +``` + +View: + +```C# +@Html.ReportViewer( + ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, + new { scrolling = "no" , DynamicID = ViewBag.DynamicID}) +``` + +## More info + +Check the [Wiki](https://github.com/armanio123/ReportViewerForMvc/wiki) for the project. \ No newline at end of file diff --git a/ReportViewerForMvc.Example/Controllers/ExamplesController.cs b/ReportViewerForMvc.Example/Controllers/ExamplesController.cs index fc41f24..f85ecc1 100644 --- a/ReportViewerForMvc.Example/Controllers/ExamplesController.cs +++ b/ReportViewerForMvc.Example/Controllers/ExamplesController.cs @@ -39,7 +39,7 @@ public ActionResult ServerReportExample() reportViewer.ServerReport.SetParameters(GetParametersServer()); ViewBag.ReportViewer = reportViewer; - + ViewBag.DynamicID = Guid.NewGuid().ToString(); return View(); } @@ -67,6 +67,7 @@ private void SetLocalReport() reportViewer.LocalReport.DataSources.Add(new ReportDataSource("dsLocalReport", tds.Tables[0])); reportViewer.LocalReport.SetParameters(GetParametersLocal()); + ViewBag.DynamicID = Guid.NewGuid().ToString(); ViewBag.ReportViewer = reportViewer; } diff --git a/ReportViewerForMvc.Example/ReportViewerForMvc.Example.csproj b/ReportViewerForMvc.Example/ReportViewerForMvc.Example.csproj index 2df113b..c01fe94 100644 --- a/ReportViewerForMvc.Example/ReportViewerForMvc.Example.csproj +++ b/ReportViewerForMvc.Example/ReportViewerForMvc.Example.csproj @@ -46,14 +46,26 @@ - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.Common.dll + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.Common.dll - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.ProcessingObjectModel.DLL + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.DataVisualization.dll - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.WebForms.DLL + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.Design.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.ProcessingObjectModel.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WebDesign.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WebForms.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WinForms.dll ..\packages\Microsoft.SqlServer.Types.14.0.314.76\lib\net40\Microsoft.SqlServer.Types.dll diff --git a/ReportViewerForMvc.Example/ReportViewerWebForm.aspx b/ReportViewerForMvc.Example/ReportViewerWebForm.aspx index d33b60a..28c631b 100644 --- a/ReportViewerForMvc.Example/ReportViewerWebForm.aspx +++ b/ReportViewerForMvc.Example/ReportViewerWebForm.aspx @@ -1,6 +1,6 @@ <%@ Page Language="C#" AutoEventWireup="True" CodeBehind="ReportViewerWebForm.aspx.cs" Inherits="ReportViewerForMvc.ReportViewerWebForm" %> -<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> +<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> diff --git a/ReportViewerForMvc.Example/SqlServerTypes/x64/SqlServerSpatial140.dll b/ReportViewerForMvc.Example/SqlServerTypes/x64/SqlServerSpatial140.dll new file mode 100644 index 0000000..6e443bf Binary files /dev/null and b/ReportViewerForMvc.Example/SqlServerTypes/x64/SqlServerSpatial140.dll differ diff --git a/ReportViewerForMvc.Example/SqlServerTypes/x64/msvcr120.dll b/ReportViewerForMvc.Example/SqlServerTypes/x64/msvcr120.dll new file mode 100644 index 0000000..67937ce Binary files /dev/null and b/ReportViewerForMvc.Example/SqlServerTypes/x64/msvcr120.dll differ diff --git a/ReportViewerForMvc.Example/SqlServerTypes/x86/SqlServerSpatial140.dll b/ReportViewerForMvc.Example/SqlServerTypes/x86/SqlServerSpatial140.dll new file mode 100644 index 0000000..590a22a Binary files /dev/null and b/ReportViewerForMvc.Example/SqlServerTypes/x86/SqlServerSpatial140.dll differ diff --git a/ReportViewerForMvc.Example/SqlServerTypes/x86/msvcr120.dll b/ReportViewerForMvc.Example/SqlServerTypes/x86/msvcr120.dll new file mode 100644 index 0000000..23447f5 Binary files /dev/null and b/ReportViewerForMvc.Example/SqlServerTypes/x86/msvcr120.dll differ diff --git a/ReportViewerForMvc.Example/Views/Examples/AnonymousExample.cshtml b/ReportViewerForMvc.Example/Views/Examples/AnonymousExample.cshtml index eb03bc5..75ad812 100644 --- a/ReportViewerForMvc.Example/Views/Examples/AnonymousExample.cshtml +++ b/ReportViewerForMvc.Example/Views/Examples/AnonymousExample.cshtml @@ -24,7 +24,8 @@ ProcessingMode = 0, //ProcessingMode.Local SizeToReportContent = true, Width = Unit.Percentage(100), - Height = Unit.Percentage(100) + Height = Unit.Percentage(100), + }, new { @@ -39,4 +40,7 @@ Name = "dsLocalReport", Value = dataList }, - null) \ No newline at end of file + new + { + DynamicID = Guid.NewGuid().ToString() + }) \ No newline at end of file diff --git a/ReportViewerForMvc.Example/Views/Examples/LocalReportExample.cshtml b/ReportViewerForMvc.Example/Views/Examples/LocalReportExample.cshtml index d45b9eb..cf7a390 100644 --- a/ReportViewerForMvc.Example/Views/Examples/LocalReportExample.cshtml +++ b/ReportViewerForMvc.Example/Views/Examples/LocalReportExample.cshtml @@ -7,6 +7,6 @@

Local report example

-@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer) +@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new {DynamicID = ViewBag.DynamicID}) diff --git a/ReportViewerForMvc.Example/Views/Examples/ServerReportExample.cshtml b/ReportViewerForMvc.Example/Views/Examples/ServerReportExample.cshtml index de70626..6afefa3 100644 --- a/ReportViewerForMvc.Example/Views/Examples/ServerReportExample.cshtml +++ b/ReportViewerForMvc.Example/Views/Examples/ServerReportExample.cshtml @@ -8,4 +8,4 @@ @Html.ReportViewer( ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, - new { scrolling = "no" }) + new { scrolling = "no" , DynamicID = ViewBag.DynamicID}) diff --git a/ReportViewerForMvc.Example/Web.config b/ReportViewerForMvc.Example/Web.config index 5a7e5e4..f97f1f8 100644 --- a/ReportViewerForMvc.Example/Web.config +++ b/ReportViewerForMvc.Example/Web.config @@ -15,16 +15,16 @@ - + - - + + - + @@ -60,7 +60,8 @@ - + + diff --git a/ReportViewerForMvc.Example/packages.config b/ReportViewerForMvc.Example/packages.config index 5e5fa42..a06f603 100644 --- a/ReportViewerForMvc.Example/packages.config +++ b/ReportViewerForMvc.Example/packages.config @@ -7,7 +7,7 @@ - + diff --git a/ReportViewerForMvc.Tests/ReportViewerForMvc.Tests.csproj b/ReportViewerForMvc.Tests/ReportViewerForMvc.Tests.csproj index 3e7df0b..971fade 100644 --- a/ReportViewerForMvc.Tests/ReportViewerForMvc.Tests.csproj +++ b/ReportViewerForMvc.Tests/ReportViewerForMvc.Tests.csproj @@ -42,14 +42,26 @@ ..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.Common.dll + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.Common.dll - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.ProcessingObjectModel.DLL + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.DataVisualization.dll - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.WebForms.DLL + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.Design.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.ProcessingObjectModel.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WebDesign.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WebForms.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WinForms.dll ..\packages\Microsoft.SqlServer.Types.14.0.314.76\lib\net40\Microsoft.SqlServer.Types.dll diff --git a/ReportViewerForMvc.Tests/SqlServerTypes/x64/SqlServerSpatial140.dll b/ReportViewerForMvc.Tests/SqlServerTypes/x64/SqlServerSpatial140.dll new file mode 100644 index 0000000..6e443bf Binary files /dev/null and b/ReportViewerForMvc.Tests/SqlServerTypes/x64/SqlServerSpatial140.dll differ diff --git a/ReportViewerForMvc.Tests/SqlServerTypes/x64/msvcr120.dll b/ReportViewerForMvc.Tests/SqlServerTypes/x64/msvcr120.dll new file mode 100644 index 0000000..67937ce Binary files /dev/null and b/ReportViewerForMvc.Tests/SqlServerTypes/x64/msvcr120.dll differ diff --git a/ReportViewerForMvc.Tests/SqlServerTypes/x86/SqlServerSpatial140.dll b/ReportViewerForMvc.Tests/SqlServerTypes/x86/SqlServerSpatial140.dll new file mode 100644 index 0000000..590a22a Binary files /dev/null and b/ReportViewerForMvc.Tests/SqlServerTypes/x86/SqlServerSpatial140.dll differ diff --git a/ReportViewerForMvc.Tests/SqlServerTypes/x86/msvcr120.dll b/ReportViewerForMvc.Tests/SqlServerTypes/x86/msvcr120.dll new file mode 100644 index 0000000..23447f5 Binary files /dev/null and b/ReportViewerForMvc.Tests/SqlServerTypes/x86/msvcr120.dll differ diff --git a/ReportViewerForMvc.Tests/packages.config b/ReportViewerForMvc.Tests/packages.config index 0478510..7bc1237 100644 --- a/ReportViewerForMvc.Tests/packages.config +++ b/ReportViewerForMvc.Tests/packages.config @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/ReportViewerForMvc/HtmlHelperExtensions.cs b/ReportViewerForMvc/HtmlHelperExtensions.cs index 6493673..82d0b80 100644 --- a/ReportViewerForMvc/HtmlHelperExtensions.cs +++ b/ReportViewerForMvc/HtmlHelperExtensions.cs @@ -26,7 +26,7 @@ public static HtmlString ReportViewer(this HtmlHelper helper, ReportViewer repor /// The HTML helper instance that this method extends. /// The object containing the ReportViewer control properties. /// The object containing the HTML attributes of the iframe. - /// An HTML iframe with the specified attributes that sets its heigh and width based on the content of the report. + /// An HTML iframe with the specified attributes that sets its height and width based on the content of the report. public static HtmlString ReportViewer(this HtmlHelper helper, ReportViewer reportViewer, object htmlAttributes) { return ReportViewerForMvc.GetIframe(reportViewer, htmlAttributes); @@ -53,7 +53,7 @@ public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewe /// The object containing the ReportViewer control properties. /// An object containing the LocalReport/ServerReport properties. /// The object containing the HTML attributes of the iframe. - /// An HTML iframe with the specified attributes that sets its heigh and width based on the content of the report. + /// An HTML iframe with the specified attributes that sets its height and width based on the content of the report. public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewer, object report, object htmlAttributes) { ReportViewer reportViewerControl = ReportViewerForMvc.AnonymousReportViewer(reportViewer, report); @@ -69,7 +69,7 @@ public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewe /// An object containing the LocalReport/ServerReport properties. /// Object that contains the parameters for a report. /// The object containing the HTML attributes of the iframe. - /// An HTML iframe with the specified attributes that sets its heigh and width based on the content of the report. + /// An HTML iframe with the specified attributes that sets its height and width based on the content of the report. public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewer, object report, object parameters, object htmlAttributes) { ReportViewer reportViewerControl = ReportViewerForMvc.AnonymousReportViewer(reportViewer, report, parameters); @@ -86,7 +86,7 @@ public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewe /// Object that contains the parameters for a report. /// The data sources to be added to the report. /// The object containing the HTML attributes of the iframe. - /// An HTML iframe with the specified attributes that sets its heigh and width based on the content of the report. + /// An HTML iframe with the specified attributes that sets its height and width based on the content of the report. public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewer, object report, object parameters, object dataSources, object htmlAttributes) { ReportViewer reportViewerControl = ReportViewerForMvc.AnonymousReportViewer(reportViewer, report, parameters, dataSources); diff --git a/ReportViewerForMvc/IframeBuilder.cs b/ReportViewerForMvc/IframeBuilder.cs index 51f31e1..06f9bf4 100644 --- a/ReportViewerForMvc/IframeBuilder.cs +++ b/ReportViewerForMvc/IframeBuilder.cs @@ -11,16 +11,16 @@ internal static HtmlString Iframe(object htmlAttributes) { IDictionary parsedHtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); - ReportViewerForMvc.IframeId = GetId(parsedHtmlAttributes); + var iframeID = GetId(parsedHtmlAttributes); - string parsedIframe = CreateIframeTag(parsedHtmlAttributes); + string parsedIframe = CreateIframeTag(parsedHtmlAttributes, iframeID); parsedIframe += ReceiveMessageScript(); - parsedIframe += SetIframeIdScript(); + parsedIframe += SetIframeIdScript(iframeID); return new HtmlString(parsedIframe); } - private static string GetId(IDictionary htmlAttributes) + public static string GetId(IDictionary htmlAttributes) { string id; @@ -41,31 +41,29 @@ private static string GetId(IDictionary htmlAttributes) return id; } - private static string CreateIframeTag(IDictionary htmlAttributes) + public static string CreateIframeTag(IDictionary htmlAttributes, string iframeID) { string applicationPath = (HttpContext.Current.Request.ApplicationPath == "/") ? "" : HttpContext.Current.Request.ApplicationPath; TagBuilder tagBuilder = new TagBuilder("iframe"); - tagBuilder.GenerateId(ReportViewerForMvc.IframeId); - tagBuilder.MergeAttribute("src", applicationPath +"/ReportViewerWebForm.aspx"); + tagBuilder.GenerateId(iframeID); + tagBuilder.MergeAttribute("src", applicationPath +"/ReportViewerWebForm.aspx?DynamicID=" + htmlAttributes["DynamicID"]); tagBuilder.MergeAttributes(htmlAttributes, false); tagBuilder.SetInnerText("iframes not supported."); return tagBuilder.ToString(); } - private static string ReceiveMessageScript() + public static string ReceiveMessageScript() { string script = ""; return script; } - private static string SetIframeIdScript() + public static string SetIframeIdScript(string iframeID) { - string script = ""; - - return script; + return ""; } } } \ No newline at end of file diff --git a/ReportViewerForMvc/ReportViewerForMvc.cs b/ReportViewerForMvc/ReportViewerForMvc.cs index 02e78d8..8ab1c60 100644 --- a/ReportViewerForMvc/ReportViewerForMvc.cs +++ b/ReportViewerForMvc/ReportViewerForMvc.cs @@ -1,5 +1,7 @@ using Microsoft.Reporting.WebForms; using System; +using System.Collections.Concurrent; +using System.Collections.Generic; using System.Web; namespace ReportViewerForMvc @@ -9,20 +11,27 @@ namespace ReportViewerForMvc /// public static class ReportViewerForMvc { - internal static string IframeId { get; set; } + private static ConcurrentDictionary reportViewerDictionary = new ConcurrentDictionary(); + private const string _staticKey = "static"; + internal static ReportViewer ReportViewer(string ID) + { + return reportViewerDictionary[ID ?? _staticKey]; + } + internal static void ReportViewer(string ID, ReportViewer reportViewer) + { + reportViewerDictionary.TryAdd(ID ?? _staticKey, reportViewer); + } - private static ReportViewer reportViewer; - internal static ReportViewer ReportViewer + internal static ReportViewer Remove(string ID ) { - get { return reportViewer; } - set - { - //TODO: Implement dynamic ID - reportViewer = value; - reportViewer.ID = "ReportViewer1"; - } + ReportViewer reportViewer; + + if (reportViewerDictionary.TryRemove(ID ?? _staticKey, out reportViewer)) + return reportViewer; + return null; } + internal static HtmlString GetIframe(ReportViewer reportViewer, object htmlAttributes) { if (reportViewer == null) @@ -30,7 +39,9 @@ internal static HtmlString GetIframe(ReportViewer reportViewer, object htmlAttri throw new ArgumentNullException("reportViewer", "Value cannot be null."); } - ReportViewerForMvc.ReportViewer = reportViewer; + var dynamicID = (string)htmlAttributes.GetType().GetProperty("DynamicID").GetValue(htmlAttributes, null); + + ReportViewer(dynamicID, reportViewer); return IframeBuilder.Iframe(htmlAttributes); } diff --git a/ReportViewerForMvc/ReportViewerForMvc.csproj b/ReportViewerForMvc/ReportViewerForMvc.csproj index 5619954..0f14ef0 100644 --- a/ReportViewerForMvc/ReportViewerForMvc.csproj +++ b/ReportViewerForMvc/ReportViewerForMvc.csproj @@ -34,14 +34,29 @@ 4 - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.Common.dll + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.Common.dll - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.ProcessingObjectModel.DLL + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.DataVisualization.dll - - ..\packages\Microsoft.Report.Viewer.11.0.0.0\lib\net\Microsoft.ReportViewer.WebForms.DLL + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.Design.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.ProcessingObjectModel.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WebDesign.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WebForms.dll + + + ..\packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.900.148\lib\net40\Microsoft.ReportViewer.WinForms.dll + + + ..\packages\Microsoft.SqlServer.Types.14.0.314.76\lib\net40\Microsoft.SqlServer.Types.dll True @@ -101,6 +116,7 @@ ReportViewerWebForm.aspx.cs Always + @@ -114,6 +130,19 @@ ASPXCodeBehind Always + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/ReportViewerForMvc/ReportViewerWebForm.aspx b/ReportViewerForMvc/ReportViewerWebForm.aspx index d33b60a..28c631b 100644 --- a/ReportViewerForMvc/ReportViewerWebForm.aspx +++ b/ReportViewerForMvc/ReportViewerWebForm.aspx @@ -1,6 +1,6 @@ <%@ Page Language="C#" AutoEventWireup="True" CodeBehind="ReportViewerWebForm.aspx.cs" Inherits="ReportViewerForMvc.ReportViewerWebForm" %> -<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> +<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> diff --git a/ReportViewerForMvc/ReportViewerWebForm.aspx.cs b/ReportViewerForMvc/ReportViewerWebForm.aspx.cs index 9a9b3e0..76164b4 100644 --- a/ReportViewerForMvc/ReportViewerWebForm.aspx.cs +++ b/ReportViewerForMvc/ReportViewerWebForm.aspx.cs @@ -1,6 +1,7 @@ using Microsoft.Reporting.WebForms; using System; using System.Web.UI.WebControls; +using Report = Microsoft.ReportingServices.Interfaces.Report; namespace ReportViewerForMvc { @@ -9,19 +10,31 @@ namespace ReportViewerForMvc /// public partial class ReportViewerWebForm : System.Web.UI.Page { + private string DynamicID; + protected void Page_Load(object sender, EventArgs e) { BuildReportViewer(); + // register eventhandler to remove the reportviewer + ReportViewer1.Disposed += ReportViewerDisposingEventHandler; } private void BuildReportViewer() { if (!IsPostBack) { - ReportViewerForMvc.ReportViewer.ID = ReportViewer1.ID; + DynamicID = Request.QueryString["DynamicID"]; + ReportViewerForMvc.ReportViewer(DynamicID).ID = ReportViewer1.ID; - ReportViewer1.SetProperties(ReportViewerForMvc.ReportViewer); + ReportViewer1.SetProperties(ReportViewerForMvc.ReportViewer(DynamicID)); } } + + protected void ReportViewerDisposingEventHandler(object sender, EventArgs e) + { + var reportViewer = ReportViewerForMvc.Remove(DynamicID); + if (reportViewer != null) + reportViewer.Dispose(); + } } } \ No newline at end of file diff --git a/ReportViewerForMvc/SqlServerTypes/Loader.cs b/ReportViewerForMvc/SqlServerTypes/Loader.cs new file mode 100644 index 0000000..ce606cf --- /dev/null +++ b/ReportViewerForMvc/SqlServerTypes/Loader.cs @@ -0,0 +1,45 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; + +namespace SqlServerTypes +{ + /// + /// Utility methods related to CLR Types for SQL Server + /// + public class Utilities + { + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + private static extern IntPtr LoadLibrary(string libname); + + /// + /// Loads the required native assemblies for the current architecture (x86 or x64) + /// + /// + /// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications + /// and AppDomain.CurrentDomain.BaseDirectory for desktop applications. + /// + public static void LoadNativeAssemblies(string rootApplicationPath) + { + var nativeBinaryPath = IntPtr.Size > 4 + ? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\") + : Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\"); + + LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll"); + LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll"); + } + + private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName) + { + var path = Path.Combine(nativeBinaryPath, assemblyName); + var ptr = LoadLibrary(path); + if (ptr == IntPtr.Zero) + { + throw new Exception(string.Format( + "Error loading {0} (ErrorCode: {1})", + assemblyName, + Marshal.GetLastWin32Error())); + } + } + } +} \ No newline at end of file diff --git a/ReportViewerForMvc/SqlServerTypes/readme.htm b/ReportViewerForMvc/SqlServerTypes/readme.htm new file mode 100644 index 0000000..02d9ac8 --- /dev/null +++ b/ReportViewerForMvc/SqlServerTypes/readme.htm @@ -0,0 +1,61 @@ + + + + Microsoft.SqlServer.Types + + + +
+

Action required to load native assemblies

+

+ To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types for SQL Server' installed you also need to deploy the native assembly SqlServerSpatial140.dll. Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\x86 and SqlServerTypes\x64 subdirectories. The native assembly msvcr120.dll is also included in case the C++ runtime is not installed. +

+

+ You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture). +

+

ASP.NET Web Sites

+

+ For ASP.NET Web Sites, add the following block of code to the code behind file of the Web Form where you have added Report Viewer Control: +

+    Default.aspx.cs:
+        
+    public partial class _Default : System.Web.UI.Page
+    {
+        static bool _isSqlTypesLoaded = false;
+
+        public _Default()
+        {
+            if (!_isSqlTypesLoaded)
+            {
+                SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~"));
+                _isSqlTypesLoaded = true;
+            }
+            
+        }
+    }
+
+

+

ASP.NET Web Applications

+

+ For ASP.NET Web Applications, add the following line of code to the Application_Start method in Global.asax.cs: +

    SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
+

+

Desktop Applications

+

+ For desktop applications, add the following line of code to run before any spatial operations are performed: +

    SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
+

+
+ + \ No newline at end of file diff --git a/ReportViewerForMvc/SqlServerTypes/x64/SqlServerSpatial140.dll b/ReportViewerForMvc/SqlServerTypes/x64/SqlServerSpatial140.dll new file mode 100644 index 0000000..6e443bf Binary files /dev/null and b/ReportViewerForMvc/SqlServerTypes/x64/SqlServerSpatial140.dll differ diff --git a/ReportViewerForMvc/SqlServerTypes/x64/msvcr120.dll b/ReportViewerForMvc/SqlServerTypes/x64/msvcr120.dll new file mode 100644 index 0000000..67937ce Binary files /dev/null and b/ReportViewerForMvc/SqlServerTypes/x64/msvcr120.dll differ diff --git a/ReportViewerForMvc/SqlServerTypes/x86/SqlServerSpatial140.dll b/ReportViewerForMvc/SqlServerTypes/x86/SqlServerSpatial140.dll new file mode 100644 index 0000000..590a22a Binary files /dev/null and b/ReportViewerForMvc/SqlServerTypes/x86/SqlServerSpatial140.dll differ diff --git a/ReportViewerForMvc/SqlServerTypes/x86/msvcr120.dll b/ReportViewerForMvc/SqlServerTypes/x86/msvcr120.dll new file mode 100644 index 0000000..23447f5 Binary files /dev/null and b/ReportViewerForMvc/SqlServerTypes/x86/msvcr120.dll differ diff --git a/ReportViewerForMvc/packages.config b/ReportViewerForMvc/packages.config index 58543ef..838aa30 100644 --- a/ReportViewerForMvc/packages.config +++ b/ReportViewerForMvc/packages.config @@ -3,6 +3,7 @@ - + + \ No newline at end of file