Re: Changing Crystal Report ReportSource dynamically via asp.net

K

kota

Use viewer.reportsource="complee phical path" like "D:/test.rpt"

I hope this may help you.

Kota.
 
H

Huzaifa Matawala

hi mrwoopey

check the below i think this is what u r looking for
public ReportDocument oRpt=new ReportDocument();

// write a if condition to check the selection

string str=Server.MapPath(report Name);
string str1=str.Replace("\\", \\\\);
oRpt.Load(str1);

//you have to pass the logon parameters for the report
CrystalDecisions.Shared.TableLogOnInfo crLogonInfo;
crLogonInfo = oRpt.Database.Tables[0].LogOnInfo;
crLogonInfo.ConnectionInfo.ServerName = Session["Server"].ToString().Trim();
crLogonInfo.ConnectionInfo.UserID =Session["dbUser"].ToString().Trim();
crLogonInfo.ConnectionInfo.Password =Session["dbPwd"].ToString();
crLogonInfo.ConnectionInfo.DatabaseName
=Session["dbName"].ToString().Trim();
oRpt.Database.Tables[0].ApplyLogOnInfo(crLogonInfo);

CrystalReportViewer1.DataBind();

CrystalReportViewer1.ReportSource = oRpt;


huzaifa
 
Joined
Oct 26, 2014
Messages
1
Reaction score
0
Try:


Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO

Public Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click

OpenPDF(Request.ApplicationPath + "/Reports/Report.pdf")

End Sub


Private Sub OpenPDF(downloadAsFilename As String)
Dim RptDoc As New ReportDocument()
RptDoc.Load(Server.MapPath(Request.ApplicationPath + "/Reports/myreport.rpt"))
RptDoc.SetDatabaseLogon("user", "password", "server", "database")

Dim stream As New BinaryReader(RptDoc.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat))
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", Convert.ToString("attachment; filename=") & downloadAsFilename)
Response.AddHeader("content-length", stream.BaseStream.Length.ToString())
Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)))
Response.Flush()
Response.Close()
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,056
Messages
2,570,446
Members
47,097
Latest member
MarionMajo

Latest Threads

Top