I have a web application where I just need to view my report embedded in a web page. I don't want CrystalReportViewer side controls like printing, zooming, paging etc. Its look and feel should be like a scanned document picture. Any help?
Yes this is possible. Here's a code snippet that converts the crystal report object (in memory stream) to Pdf, Word, or Excel.
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
ReportDocument rpt = new ReportDocument();
string path2 = path + reportName;
rpt.Load(path2);
CrystalDecisions.CrystalReports.Engine.Database crDatabase = rpt.Database;
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = server;
crConnectionInfo.DatabaseName = db;
crConnectionInfo.UserID = crystalUser;
crConnectionInfo.Password = pwd;
crConnectionInfo.IntegratedSecurity = false;
<<<<<<report logic here>>>>>>>>>>>
CrystalDecisions.Shared.ExportFormatType typ = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
if (exportFormatType == "doc")
typ = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
if (exportFormatType == "xls")
typ = CrystalDecisions.Shared.ExportFormatType.Excel;
MemoryStream ms = (MemoryStream)rpt.ExportToStream(typ);
Related
I need to pass a parameter to reporting services which is on the reporting services server on my computer from my asp.net. The parameter is SellerID
MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
MyReportViewer.ServerReport.ReportServerUrl = New Uri("http://jean-daniel/ReportServer_SQLEXPRESSADDD")
' Report Server URL
MyReportViewer.ServerReport.ReportPath = "/Report Project2/Auction History"
' Report Name
MyReportViewer.ShowParameterPrompts = False
MyReportViewer.ShowToolBar = False
MyReportViewer.ServerReport.Refresh()
Dim params(0) As ReportParameter
params(0) = New ReportParameter("SellerID", "201", False)
MyReportViewer.ServerReport.SetParameters(params)
MyReportViewer.ServerReport.Refresh()
Any idea on how to do this?
To pass parameters to a report via code you have to do it like this:
C#:
ReportParameter[] params = new ReportParameter[1];
params[0] = new ReportParameter("SellerId", ParameterValue , false);
MyReportViewer.ServerReport.SetParameters(params);
MyReportViewer.ServerReport.Refresh();
VB.NET:
Dim params(0) As ReportParameter
params(0) = New ReportParameter("SellerId", "YourValue", false)
MyReportViewer.ServerReport.SetParameters(params);
MyReportViewer.ServerReport.Refresh();
Here you can find a complete example Generate SQL Server Reporting Services (SSRS) Report as PDF from URL with VB.NET or C#.NET
I having trouble displaying a Crystal report on a ASP.Net web page. The website is an internal website only so you'll see that I have file path coded into the site. I think I'm very close the getting this to work, but I'm obviously missing something. Can anyone help?
He is my code:
void BindReport()
{
ReportDocument rd = new ReportDocument();
//Report is saved on an external server which I have full access too
rd.Load(#"\\MyServer\Reports\MyReport.rpt");
rd.SetDatabaseLogon("UserName", "Password", "MyServer", "MyDatabase", true);
//The Report has 2 parameter and links directly to a stored procedure on a SQL Server
rd.SetParameterValue("#uspDateFrom", new DateTime(2012, 05, 01));
rd.SetParameterValue("#uspDateTo", new DateTime(2012, 05, 31));
CrystalReportViewer1.ReportSource = rd;
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
CrystalReportViewer1.RefreshReport();
}
//I call my report on a button click
protected void buttonPreviewReport_Click(object sender, EventArgs e)
{
BindReport();
}
When the report tries to run I get a dialog box pop up asking for my parameter values even though I've already passed them in!? and even if I enter them on the dialog prompt I then receive a message saying that no valid report source is available.
Anybody got any ideas?
I'm using ASP.Net 4.0
Thanks in advance
Same Problem I was getting once when I was working with Crystal Report.
ParameterFields paramFields = new ParameterFields();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
paramField.ParameterFieldName = "#examid";// This is how you can send Parameter Value to the Crystal Report
// Set the first discrete value and pass it to the parameter.
discreteVal.Value = ddlAllExam.SelectedValue;//Value from DropDown
paramField.CurrentValues.Add(discreteVal);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
string datasource = System.Configuration.ConfigurationManager.AppSettings["Data Source"].ToString();
string Database = System.Configuration.ConfigurationManager.AppSettings["Database"].ToString();
string Userid = System.Configuration.ConfigurationManager.AppSettings["Userid"].ToString();
string Password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString();
ReportDocument report = new ReportDocument();
report.Load(Server.MapPath("~/Reports/AllExamReport.rpt"));//Here you can give the Path of external Server
report.SetDatabaseLogon(Userid, Password, datasource, Database);
CrystalReportViewer1.ReportSource = report;
Hope this will help you.!!!
I have a problem with my crystal reports in Visual Studio 2008, and after searching and searching I got nothing.
My file CrystalReportxxx.rpt has an xsd file as dataschema. A datatable is created and it's passed to report as datasource. To fill the datatable, my application connects to Oracle database.
For showing rows or data with CrystalReportViewer, the report needs credentials like logid and password of database. However, if I export this report to a PDF file, then no credentials are needed and PDF file shows all rows.
This is my code:
Dim dt As DataTable
FunctionsOP.CreaDataTable("pkg_list.sp_list", True, ospEntry,
dt)
Dim oRpt As New Reportes.CrystalReportxxx
oRpt.SetDatabaseLogon("userxxx", "passwordxxx")
oRpt.SetDataSource(dt)
CrystalReportViewer1.EnableDatabaseLogonPrompt = False
CrystalReportViewer1.ReportSource = oRpt
CrystalReportViewer1.DataBind()
CrystalReportViewer1.Dispose()
I suppose that when setting:
oRpt.SetDatabaseLogon("userxxx", "passwordxxx")
and report shows no data, is because credentials are wrong.
My question is: How to bypass this credential input?
Is it mandatory to input userid, password, etc for using a xsd file in my Crystal
Report?
What is strange to me is that when I export that report to PDF, there is no
problem. Data is shown OK and no credential is needed:
Dim exportOpts As ExportOptions = oRpt.ExportOptions
oRpt.ExportOptions.ExportFormatType =
ExportFormatType.PortableDocFormat
oRpt.ExportOptions.ExportDestinationType =
ExportDestinationType.DiskFile
oRpt.ExportOptions.DestinationOptions = New
DiskFileDestinationOptions
CType(oRpt.ExportOptions.DestinationOptions,
DiskFileDestinationOptions).DiskFileName = Server.MapPath("../Temp/" +
PDFName)
oRpt.Export()
oRpt.Close()
oRpt.Dispose()
I also tried this code:
Dim dt1 As New DataTable : Dim dt2 As New DataTable
Dim oRpt As New Reportes.CR_IndicadorA11
Dim ParRep As ReportClass = oRpt
SetConnectionsReports(ParRep)
FunctionsOP.CreaDataTable("pkg_Listar_Tipos.sp_indicador_a11_sum", True, Nothing, dt1)
FunctionsOP.CreaDataTable("pkg_Listar_Tipos.sp_indicador_a11_det", True, Nothing, dt2)
oRpt.SetDataSource(dt1)
oRpt.OpenSubreport("CR_sub_indicadorA11_det.rpt").SetDataSource(dt2)
CrystalReportViewer1.Visible = True
CrystalReportViewer1.EnableDatabaseLogonPrompt = False
CrystalReportViewer1.ReportSource = oRpt
CrystalReportViewer1.DataBind()
CrystalReportViewer1.Dispose()
Public Sub SetConnectionsReports(ByRef Rpt As ReportClass)
Dim server, base, user, pass As String
server = "SRVBDDESA2.DOMINTERN0XXX.LOCAL" ' also with IP number is the same
base = "DESAOPINT"
user = "ORGPOL"
pass = "desarrollo"
For Each connection As IConnectionInfo In Rpt.DataSourceConnections
connection.SetConnection(server, base, user, pass)
Next
End Sub
I'm using crystal reports to build reports, everything is ok while development.
But after deployment of website, print functionality doesn't work.
I use _rptDocument.PrintToPrinter(1, false, 0, 0); to print report.
I've tried two methods to deploy website
Normal Publish option.
Web Deployment Project.
But I got the same output, print functionality doesn't work.
Also, I tried to set default printer, this also doesn't work.
Any ideas?
Printing on a web server isn`t a good idea. What should happen? A user prints on your servers printer? Use CR to create PDFs. Stream them to your clients. They can use their local printers.
try this :- Create PDF and open Browser Tab ...enter code here
string fname = "Report" + ".pdf";`enter code here`
//Create instance for crystal report Export option class
ExportOptions exprtopt = default(ExportOptions);
//create instance for destination option - This one is used to set path of your pdf file save
DiskFileDestinationOptions destiopt = new DiskFileDestinationOptions();
//Bind data in the crystal report first before export cystal report to PDF
ReportDocument RptDoc = new ReportDocument();
//Map your crystal report path
// RD.Load(Server.MapPath("~/CrystalReport2.rpt"));
//Set your crystal report datasource as dt
//Get path and assign into destination DiskFileName
destiopt.DiskFileName = Server.MapPath(fname);
exprtopt = RD.ExportOptions;
exprtopt.ExportDestinationType = ExportDestinationType.DiskFile;
//use PortableDocFormat for PDF data
exprtopt.ExportFormatType = ExportFormatType.PortableDocFormat;
exprtopt.DestinationOptions = destiopt;
//finally export your report document
RD.Export();
//To open your PDF after save it from crystal report
string Path = Server.MapPath(fname);
//create instance to client to open your pdf
WebClient client = new WebClient();
//Assign path to download pdf
Byte[] buffer = client.DownloadData(Path);
//metion content type as PDF and write
// Response.ContentType = "application/pdf";
//Response.AddHeader("content-length", buffer.Length.ToString());
//Response.BinaryWrite(buffer);
//======================================
Response.Write("<script>");
Response.Write("window.open('" + fname + "', '_newtab');");
Response.Write("</script>");
//===================================
IMTIYAZ
I'm looking for a little help on programmatically passing parameters to a SSRS report via VB.NET and ASP.NET. This seems like it should be a relatively simple thing to do, but I haven't had much luck finding help on this.
Does anyone have any suggestions on where to go to get help with this, or perhaps even some sample code?
Thanks.
You can do the following,: (it works both on local reports as in Full Blown SSRS reports. but in full mode, use the appropriate class, the parameter part remains the same)
LocalReport myReport = new LocalReport();
myReport.ReportPath = Server.MapPath("~/Path/To/Report.rdlc");
ReportParameter myParam = new ReportParameter("ParamName", "ParamValue");
myReport.SetParameters(new ReportParameter[] { myParam });
// more code here to render report
If the Report server is directly accessible, you can pass parameters in the Querystring if you are accessing the repoort with a URL:
http://MyServer/ReportServer/?MyReport&rs:Command=Render&Param1=54321&Param2=product
You can add output formatting by adding the following on the end of the URL:
&rs:Format=Excel
or
&rs:Format=PDF
It's been a while since I did this code, but it may help:
Your web project has to be a Web Site, and not a project of type "ASP.Net Web Application", or you won't be able to add the reference mentioned below.
Right click on the project and add an ASP.Net folder - App_WebReferences. You'll have to specify the server where your SRS is; choose the .asmx.
Once it's added, the folder under that level is called RSService, and under that are 2 things: reportservice.discomap & .wsdl.
In my VB, I do Imports RSService and Imports System.Web.Services.Protocols, then...
Dim MyRS As New ReportingService
The reporting service is on a different server than the webserver the app is on, so I can't do the following: MyRS.Credentials = System.Net.CredentialCache.DefaultCredentials
Instead: MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3),
where the rs1/2/3 are the login to SRS box, password to SRS box, & domain name". (These are encrypted in my web.config.)
Then, a mass-paste:
MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3)
Dim ReportByteArray As Byte() = Nothing
Dim ReportPath As String = "/SRSSiteSubFolder/ReportNameWithoutRDLExtension"
Dim ReportFormat As String = "PDF"
Dim HistoryID As String = Nothing
Dim DevInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
'Dim x As ReportParameter - not necessary
Dim ReportParams(0) As ParameterValue
ReportParams(0) = New ParameterValue()
ReportParams(0).Name = "TheParamName"
ReportParams(0).Value = WhateverValue
Dim Credentials As DataSourceCredentials() = Nothing
Dim ShowHideToggle As String = Nothing
Dim Encoding As String
Dim MimeType As String
Dim ReportHistoryParameters As ParameterValue() = Nothing
Dim Warnings As Warning() = Nothing
Dim StreamIDs As String() = Nothing
'Dim sh As New SessionHeader() - not necessary
''MyRS.SessionHeaderValue = sh - not necessary
ReportByteArray = MyRS.Render(ReportPath, ReportFormat, HistoryID, DevInfo, ReportParams, Credentials, _
ShowHideToggle, Encoding, MimeType, ReportHistoryParameters, Warnings, StreamIDs)
'(Yay! That line was giving "HTTP error 401 - Unauthorized", until I set the credentials
' as above, as explained by http://www.odetocode.com/Articles/216.aspx.)
'Write the contents of the report to a PDF file:
Dim fs As FileStream = File.Create(FullReportPath, ReportByteArray.Length)
fs.Write(ReportByteArray, 0, ReportByteArray.Length)
fs.Close()
Call EmailTheReport(FullReportPath)
If IO.File.Exists(FullReportPath) Then
IO.File.Delete(FullReportPath)
End If
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.Reset();
Label1.Visible = false;
ReportViewer1.Visible = true;
DataSet dataSet = new DataSet();
dataSet = new ClassBLL().Load_Report_Detail(TextBox1.Text,
ddlType.SelectedValue, levelcode, fields);
ReportDataSource datasource = new ReportDataSource("DataSet_StoreprocedureName",
dataSet.Tables[0]);
if (dataSet.Tables[0].Rows.Count == 0)
{
ReportViewer1.Visible = false;
}
ReportViewer1.LocalReport.ReportPath = Server.MapPath("") + #"\Report.rdlc";
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
string fields="name,girish,Z0117";
string[] filedName = fields.Split(',');
ReportParameter[] param = new ReportParameter[2];
//for (int i = 0; i < filedName.Length; i++)
//{
param[0] = new ReportParameter(filedName[0], filedName[0], true);
param[1] = new ReportParameter(filedName[3], filedName[3], true);
// }
ReportViewer1.LocalReport.SetParameters(param);
ReportViewer1.ServerReport.Refresh();