SSRS
-- =============================================
-- Author:
-- Date created: 2020-06-05
-- =============================================
Document Map show/hide by setting below two property
rpt.AsyncRendering = true;
rpt.SizeToReportContent = false;
rpt.ShowCredentialPrompts = false;
rpt.ShowParameterPrompts = false;
rpt.AsyncRendering = true;
rpt.SizeToReportContent = false;
rpt.KeepSessionAlive = false;
https://docs.microsoft.com/en-us/sql/reporting-services/report-builder/tutorial-create-a-quick-chart-report-offline-report-builder?view=sql-server-ver15
https://techbrij.com/ssrs-report-asp-net-mvc-app
https://alanjuden.com/2016/11/10/mvc-net-core-report-viewer/
Sample code
ASPX page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestReport.aspx.cs" Inherits="TestReport" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="testRW" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" ProcessingMode="Remote" Width="100%"></rsweb:ReportViewer>
</div>
</form>
</body>
</html>
Code C#
testRW.ProcessingMode = ProcessingMode.Remote;
testRW.ServerReport.ReportServerUrl = new Uri("SErviceURL");
testRW.ShowPrintButton = true;
IReportServerCredentials irsc = new CustomReportCredentials(user, password, "domain");
testRW.ServerReport.ReportServerCredentials = irsc;
testRW.ServerReport.ReportPath = "Path
testRW.ShowCredentialPrompts = false;
testRW.ShowParameterPrompts = false;
testRW.AsyncRendering = false;
testRW.SizeToReportContent = true;
testRW.ServerReport.Refresh();";
Custom PDF download
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewReport.aspx.cs" Inherits="WinBeatCloudReport.ViewReport" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function () {
// var table = $("table[title='Refresh']");
$("a[title='Word']").removeAttr('onclick');
$("a[title='PDF']").removeAttr('onclick');
$("table[title='Refresh']").hide();
$("a[title='PowerPoint']").hide();
$("a[title='TIFF file']").hide();
$("a[title='MHTML (web archive)']").hide();
$("a[title='XML file with report data']").hide();
$("a[title='Data Feed']").hide();
$("a[title='CSV (comma delimited)']").hide();
$("a[title='Excel']").hide();
$("table[title='Go back to the parent report']").hide();
$("a[title='Word']").click(function () {
$("[id*=docBtn]").click();
});
$("a[title='PDF']").click(function () {
$("[id*=pdfBtn]").click();
});
});
</script>
</head>
<body style="width: auto;height:auto;" >
<form id="form1" runat="server" style="width: auto;height:auto;">
<div style="display:none;">
<asp:Button runat="server" ID="pdfBtn" Text="PDF" OnClick="PdfButton_Click" />
<asp:Button runat="server" Text="Doc" ID="docBtn" OnClick="DocButton_Click" />
<asp:TextBox runat="server" ID="txtDocumentMapVisible"></asp:TextBox>
</div>
<div style="width: auto;height:auto;">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="rptvw" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" ProcessingMode="Remote" Width="100%" AsyncRendering="false" SizeToReportContent="false" DocumentMapWidth="120" ></rsweb:ReportViewer>
<rsweb:ReportViewer ID="PDFReportViewer" visible="false" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" ProcessingMode="Remote" Width="100%" AsyncRendering="false" DocumentMapWidth="120" ></rsweb:ReportViewer>
</div>
</form>
</body>
</html>
protected void PdfButton_Click(object sender, EventArgs e)
{
string format = "PDF",
devInfo = @"<DeviceInfo><Toolbar>True</Toolbar></DeviceInfo>";
//out parameters
string mimeType = "",
encoding = "",
fileNameExtn = "";
string[] stearms = null;
Microsoft.Reporting.WebForms.Warning[] warnings = null;
byte[] result = null;
try
{
//render report, it will returns bite array
result = PDFReportViewer.ServerReport.Render(format,
devInfo, out mimeType, out encoding,
out fileNameExtn, out stearms, out warnings);
Response.Clear();
MemoryStream ms = new MemoryStream(result);
// Response.ContentType = "application/msword";
// Response.AddHeader("Content-Disposition", "Attachment; filename=RenewalSummary.docx");
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=RenewalSummary.pdf");
Response.Buffer = true;
ms.WriteTo(Response.OutputStream);
Response.End();
}
catch (Exception ex)
{
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtDocumentMapVisible.Text = "true";
XmlDocument xDoc = new XmlDocument();
rptvw.ProcessingMode = ProcessingMode.Remote;
rptvw.ServerReport.ReportServerUrl = new Uri(serverURL);
rptvw.ShowPrintButton = true;
IReportServerCredentials irsc = new CustomReportCredentials(user, password, "");
rptvw.ServerReport.ReportServerCredentials = irsc;
if (!string.IsNullOrEmpty(Request.QueryString["SessionId"]))
{
string requestTemplatePath = Server.MapPath("~\\SessionData\\" + Request.QueryString["SessionId"].ToString() + "\\ReportingTemplate.xml");
if (System.IO.File.Exists(requestTemplatePath))
{
XmlDocument xDocTemp = new XmlDocument();
xDoc.Load(requestTemplatePath);
ReportingTemplate objReportingTemplate = Serializer.DeserializeObject<ReportingTemplate>(xDoc.InnerXml.ToString());
xDocTemp.LoadXml(objReportingTemplate.ReportDataValue.ToString());
//Delete request directory
string requestDirectoryPath = Server.MapPath("~\\SessionData\\" + Request.QueryString["SessionId"].ToString());
Directory.Delete(requestDirectoryPath, true);
rptvw.ServerReport.ReportPath = "/" + ConfigurationManager.AppSettings["ReportPath"].ToString() + objReportingTemplate.ReportName;
ReportParameter[] rptParams = new ReportParameter[xDocTemp.FirstChild.ChildNodes.Count-2];
int count = 0;
foreach (XmlNode item in xDocTemp.FirstChild.ChildNodes)
{
// if (item.Name.ToLower() == "DocumentMapRootNode" || item.Name.ToLower() == "DocumentMapVisible")
if (item.Name.ToLower()== "documentmaprootnode" || item.Name.ToLower() == "documentmapvisible")
{
if (item.Name.ToLower() == "documentmaprootnode")
{
if (!string.IsNullOrEmpty(item.InnerText))
{
rptvw.ServerReport.DisplayName = item.InnerText.Trim();
}
else
{
rptvw.ServerReport.DisplayName = "Root";
}
}
if (item.Name.ToLower() == "documentmapvisible")
{
if (!string.IsNullOrEmpty(item.InnerText))
{
txtDocumentMapVisible.Text = item.InnerText.Trim();
if (item.InnerText.Trim().ToLower() == "true")
{
txtDocumentMapVisible.Text = "true";
rptvw.DocumentMapCollapsed = false;
}
else
{
txtDocumentMapVisible.Text = "false";
rptvw.DocumentMapCollapsed = true;
}
}
else
{
txtDocumentMapVisible.Text = "false";
rptvw.DocumentMapCollapsed = true;
}
}
}
else
{
if (item.Name.ToLower().Contains("date") && item.InnerText == "")
{
rptParams[count++] = new ReportParameter(item.Name, (string)null);
}
else
{
rptParams[count++] = new ReportParameter(item.Name, item.InnerText);
}
}
}
rptvw.ServerReport.SetParameters(rptParams);
rptvw.ShowCredentialPrompts = false;
rptvw.ShowParameterPrompts = false;
rptvw.AsyncRendering = true;
rptvw.SizeToReportContent = false;
rptvw.KeepSessionAlive = false;
//rptvw.ServerReport.GetTotalPages();
//rptvw.ShowBackButton = true;
rptvw.ServerReport.Refresh();
// System.Drawing.Printing.PageSettings ps = new System.Drawing.Printing.PageSettings();
// ps.Landscape = true;
// ps.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1170);
// ps.PaperSize.RawKind = (int)System.Drawing.Printing.PaperKind.A4;
// rptvw.SetPageSettings(ps);
PDFReportViewer.ProcessingMode = ProcessingMode.Remote;
PDFReportViewer.ServerReport.ReportServerUrl = new Uri(serverURL);
PDFReportViewer.ServerReport.ReportServerCredentials = irsc;
PDFReportViewer.ServerReport.ReportPath = "/" + ConfigurationManager.AppSettings["ReportPath"].ToString() + objReportingTemplate.ReportName;
PDFReportViewer.ServerReport.SetParameters(rptParams);
PDFReportViewer.ShowCredentialPrompts = false;
PDFReportViewer.ShowParameterPrompts = false;
PDFReportViewer.AsyncRendering = true;
PDFReportViewer.SizeToReportContent = false;
PDFReportViewer.KeepSessionAlive = false;
//rptvw.ServerReport.GetTotalPages();
//rptvw.ShowBackButton = true;
PDFReportViewer.ServerReport.Refresh();
}
}
}
}
Credentials->Use this user name and password (for dynamic data source)
-- Author:
-- Date created: 2020-06-05
-- =============================================
Document Map show/hide by setting below two property
rpt.AsyncRendering = true;
rpt.SizeToReportContent = false;
rpt.ShowCredentialPrompts = false;
rpt.ShowParameterPrompts = false;
rpt.AsyncRendering = true;
rpt.SizeToReportContent = false;
rpt.KeepSessionAlive = false;
https://docs.microsoft.com/en-us/sql/reporting-services/report-builder/tutorial-create-a-quick-chart-report-offline-report-builder?view=sql-server-ver15
https://techbrij.com/ssrs-report-asp-net-mvc-app
https://alanjuden.com/2016/11/10/mvc-net-core-report-viewer/
Sample code
ASPX page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestReport.aspx.cs" Inherits="TestReport" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="testRW" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" ProcessingMode="Remote" Width="100%"></rsweb:ReportViewer>
</div>
</form>
</body>
</html>
Code C#
testRW.ProcessingMode = ProcessingMode.Remote;
testRW.ServerReport.ReportServerUrl = new Uri("SErviceURL");
testRW.ShowPrintButton = true;
IReportServerCredentials irsc = new CustomReportCredentials(user, password, "domain");
testRW.ServerReport.ReportServerCredentials = irsc;
testRW.ServerReport.ReportPath = "Path
testRW.ShowCredentialPrompts = false;
testRW.ShowParameterPrompts = false;
testRW.AsyncRendering = false;
testRW.SizeToReportContent = true;
testRW.ServerReport.Refresh();";
Custom PDF download
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewReport.aspx.cs" Inherits="WinBeatCloudReport.ViewReport" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function () {
// var table = $("table[title='Refresh']");
$("a[title='Word']").removeAttr('onclick');
$("a[title='PDF']").removeAttr('onclick');
$("table[title='Refresh']").hide();
$("a[title='PowerPoint']").hide();
$("a[title='TIFF file']").hide();
$("a[title='MHTML (web archive)']").hide();
$("a[title='XML file with report data']").hide();
$("a[title='Data Feed']").hide();
$("a[title='CSV (comma delimited)']").hide();
$("a[title='Excel']").hide();
$("table[title='Go back to the parent report']").hide();
$("a[title='Word']").click(function () {
$("[id*=docBtn]").click();
});
$("a[title='PDF']").click(function () {
$("[id*=pdfBtn]").click();
});
});
</script>
</head>
<body style="width: auto;height:auto;" >
<form id="form1" runat="server" style="width: auto;height:auto;">
<div style="display:none;">
<asp:Button runat="server" ID="pdfBtn" Text="PDF" OnClick="PdfButton_Click" />
<asp:Button runat="server" Text="Doc" ID="docBtn" OnClick="DocButton_Click" />
<asp:TextBox runat="server" ID="txtDocumentMapVisible"></asp:TextBox>
</div>
<div style="width: auto;height:auto;">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="rptvw" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" ProcessingMode="Remote" Width="100%" AsyncRendering="false" SizeToReportContent="false" DocumentMapWidth="120" ></rsweb:ReportViewer>
<rsweb:ReportViewer ID="PDFReportViewer" visible="false" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" ProcessingMode="Remote" Width="100%" AsyncRendering="false" DocumentMapWidth="120" ></rsweb:ReportViewer>
</div>
</form>
</body>
</html>
protected void PdfButton_Click(object sender, EventArgs e)
{
string format = "PDF",
devInfo = @"<DeviceInfo><Toolbar>True</Toolbar></DeviceInfo>";
//out parameters
string mimeType = "",
encoding = "",
fileNameExtn = "";
string[] stearms = null;
Microsoft.Reporting.WebForms.Warning[] warnings = null;
byte[] result = null;
try
{
//render report, it will returns bite array
result = PDFReportViewer.ServerReport.Render(format,
devInfo, out mimeType, out encoding,
out fileNameExtn, out stearms, out warnings);
Response.Clear();
MemoryStream ms = new MemoryStream(result);
// Response.ContentType = "application/msword";
// Response.AddHeader("Content-Disposition", "Attachment; filename=RenewalSummary.docx");
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=RenewalSummary.pdf");
Response.Buffer = true;
ms.WriteTo(Response.OutputStream);
Response.End();
}
catch (Exception ex)
{
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtDocumentMapVisible.Text = "true";
XmlDocument xDoc = new XmlDocument();
rptvw.ProcessingMode = ProcessingMode.Remote;
rptvw.ServerReport.ReportServerUrl = new Uri(serverURL);
rptvw.ShowPrintButton = true;
IReportServerCredentials irsc = new CustomReportCredentials(user, password, "");
rptvw.ServerReport.ReportServerCredentials = irsc;
if (!string.IsNullOrEmpty(Request.QueryString["SessionId"]))
{
string requestTemplatePath = Server.MapPath("~\\SessionData\\" + Request.QueryString["SessionId"].ToString() + "\\ReportingTemplate.xml");
if (System.IO.File.Exists(requestTemplatePath))
{
XmlDocument xDocTemp = new XmlDocument();
xDoc.Load(requestTemplatePath);
ReportingTemplate objReportingTemplate = Serializer.DeserializeObject<ReportingTemplate>(xDoc.InnerXml.ToString());
xDocTemp.LoadXml(objReportingTemplate.ReportDataValue.ToString());
//Delete request directory
string requestDirectoryPath = Server.MapPath("~\\SessionData\\" + Request.QueryString["SessionId"].ToString());
Directory.Delete(requestDirectoryPath, true);
rptvw.ServerReport.ReportPath = "/" + ConfigurationManager.AppSettings["ReportPath"].ToString() + objReportingTemplate.ReportName;
ReportParameter[] rptParams = new ReportParameter[xDocTemp.FirstChild.ChildNodes.Count-2];
int count = 0;
foreach (XmlNode item in xDocTemp.FirstChild.ChildNodes)
{
// if (item.Name.ToLower() == "DocumentMapRootNode" || item.Name.ToLower() == "DocumentMapVisible")
if (item.Name.ToLower()== "documentmaprootnode" || item.Name.ToLower() == "documentmapvisible")
{
if (item.Name.ToLower() == "documentmaprootnode")
{
if (!string.IsNullOrEmpty(item.InnerText))
{
rptvw.ServerReport.DisplayName = item.InnerText.Trim();
}
else
{
rptvw.ServerReport.DisplayName = "Root";
}
}
if (item.Name.ToLower() == "documentmapvisible")
{
if (!string.IsNullOrEmpty(item.InnerText))
{
txtDocumentMapVisible.Text = item.InnerText.Trim();
if (item.InnerText.Trim().ToLower() == "true")
{
txtDocumentMapVisible.Text = "true";
rptvw.DocumentMapCollapsed = false;
}
else
{
txtDocumentMapVisible.Text = "false";
rptvw.DocumentMapCollapsed = true;
}
}
else
{
txtDocumentMapVisible.Text = "false";
rptvw.DocumentMapCollapsed = true;
}
}
}
else
{
if (item.Name.ToLower().Contains("date") && item.InnerText == "")
{
rptParams[count++] = new ReportParameter(item.Name, (string)null);
}
else
{
rptParams[count++] = new ReportParameter(item.Name, item.InnerText);
}
}
}
rptvw.ServerReport.SetParameters(rptParams);
rptvw.ShowCredentialPrompts = false;
rptvw.ShowParameterPrompts = false;
rptvw.AsyncRendering = true;
rptvw.SizeToReportContent = false;
rptvw.KeepSessionAlive = false;
//rptvw.ServerReport.GetTotalPages();
//rptvw.ShowBackButton = true;
rptvw.ServerReport.Refresh();
// System.Drawing.Printing.PageSettings ps = new System.Drawing.Printing.PageSettings();
// ps.Landscape = true;
// ps.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1170);
// ps.PaperSize.RawKind = (int)System.Drawing.Printing.PaperKind.A4;
// rptvw.SetPageSettings(ps);
PDFReportViewer.ProcessingMode = ProcessingMode.Remote;
PDFReportViewer.ServerReport.ReportServerUrl = new Uri(serverURL);
PDFReportViewer.ServerReport.ReportServerCredentials = irsc;
PDFReportViewer.ServerReport.ReportPath = "/" + ConfigurationManager.AppSettings["ReportPath"].ToString() + objReportingTemplate.ReportName;
PDFReportViewer.ServerReport.SetParameters(rptParams);
PDFReportViewer.ShowCredentialPrompts = false;
PDFReportViewer.ShowParameterPrompts = false;
PDFReportViewer.AsyncRendering = true;
PDFReportViewer.SizeToReportContent = false;
PDFReportViewer.KeepSessionAlive = false;
//rptvw.ServerReport.GetTotalPages();
//rptvw.ShowBackButton = true;
PDFReportViewer.ServerReport.Refresh();
}
}
}
}
Implement Dynamic Data Sources in SQL Server Reporting Services:
Note: need to set
Comments
Post a Comment