Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Reports in VS2008 - Need Beginner's Tutorial

Status
Not open for further replies.

joshbula

Technical User
Nov 19, 2004
45
US
Hello, I'm looking for a tutorial for the Crystal Reports Viewer...

I'm using Visual Studio 2008 to develop a VB.NET web app.

I have a query in a TableAdaper in a DataSet. I have figured out how to create and layout a simple Crystal Report using that schema. How do I bind the DataSet query to it (with parameters) and have it download as a pdf?

I have Googled for hours and tried to go through some stuff on MSDN, but no luck. The BusinessObjects tutorials seem to be gone now that SAP took them over.

If you know of any good step-by-step instructions with clear and easy-to-understand examples, I would greatly appreciate a link or two.

Thanks,
...Josh
 
unfortunately there isn't much information on the topic.

what you want is a generic handler(ashx) to stream a pdf to the browser. it would look something like this. I'm sure there are errors with member names, but they are close.
Code:
public class MyHandler : IHttpHandler
{
   public void Process(HttpContext context)
   {
        //pull values from form/querystring/items/etc.
        //Params is a convenient abstraction to all of that.
        var id = Convert.ToInt32(context.Params["..."]);

        context.Response.ContentType = "application/pdf";
        context.Response.AddHeader("Content-Disposition", "attachment;filename=whatever.name.you.decide.pdf");
        //attachment can also be 'inline'

        using(var report = new ReportDocument())
        {
            report.Load("path to report");
            report.SetParameterField("name", value);
            report.SetDataSource(getData(id));
            report.ExportToHttpStream(context.Response.OutputStream);
        }
   }

   private DataTable getData(int id)
   {
      //code to return datatable;
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi all, thanks for your help, but I am still really struggling with this. I have tried several tutorials but many leave out information they assume I already know but don't.

I looked through the link from Turkbear above, but most of it went over my head and I wasn't really sure what I was looking for there. Jason, I keep getting the error "'ExportToHttpStream' is not a member of 'CrystalDecisions.CrystalReports.Engine.ReportDocument'" and I'm not sure what should be in the getData(ID) function to get the data from my DataSet.


Please help me find a step-by-step tutorial or FAQ that will walk me through everything from pulling the data from the DataSet, to exporting the report as a pdf file.

I'm very "novice" to asp.net and visual basic, so treat me like a 5-year old. :) This seems like such a common task I don't understand why it is so difficult, but for some reason it is.

Thanks,
...Josh
 
"'ExportToHttpStream' is not a member of 'CrystalDecisions.CrystalReports.Engine.ReportDocument'"
this means that ExportToHttpStream is not the name of the function. the name of the member is something else. I can't remember it off the top of my head. use MSDN and the f1 help to find a list of members associated with the ReportDocument object. You'll find it in the list there.

getData(ID)
this is code that you write.

Please help me find a step-by-step tutorial or FAQ that will walk me through everything from pulling the data from the DataSet, to exporting the report as a pdf file.

I'm very "novice" to asp.net and visual basic, so treat me like a 5-year old. :) This seems like such a common task I don't understand why it is so difficult, but for some reason it is.
I'll be blunt; no. You are a professional. asking us to do your work for you is unacceptable.

Rather than blindly copy and paste code, learn the concepts and understand the principles of how to utilize the .net framework (OOP and design patterns as well). From there it doesn't matter what the scenario is, you'll have the skills to code a solution.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
I'm not a professional... like I said, I am a novice just learning this and just looking for a little guidance. That is why the title of this thread implies that I'm looking for a Tutorial, not for someone to do my work for me.

I AM in the process of learning the principles of .net, and making fairly significant progress thanks in part to the wonderful and helpful people on these forums and the books that I'm reading, but like you said in the first reply, unfortunately there isn't much info on this topic.

Perhaps part of my confusion is also trying to translate between C# and VB, but either way, if you can help by pointing me to a learning resource (which is what I originally asked for... not for you to write my code for me) than I would appreciate it, but if not, no need to write anything.

Thanks,
...Josh
 
Hi,
On the site I gave you are tutorials -
Did you download:
Crystal Reports .NET SDK - Tutorial Sample Code
and
Crystal Reports .NET SDK - Additional Conceptual Documentation and Tutorials - (Download)

in addition to:
Crystal Reports 10 .NET SDK Guide



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Josh - Here's an example of the code that I am using in my first web app to do the same thing that you want to do. I am passing two parameters and then pulling the report into a pdf where the user can either print it or save it to their disk. It is in VB2008.

Private Sub Load_Report()
CRViewer1.Visible = True
crReport = New CrystalReport1
CRViewer1.Zoom(100)
crReport.SetParameterValue("LocID", inTxtLocID.Text)
crReport.SetParameterValue("CustID", inTxtCust.Text)

CRViewer1.ReportSource = crReport
CRViewer1.ShowFirstPage()
ExportData(crReport)
crReport.Dispose()
crReport.Close()
RSGConn.ConnectionString = "DSN=RSG"
RSGConn.Open()
If inTxtCust.Text <> "" Then
strsql = "DELETE from TmpPrtTkt WHERE CUSTOMERID = '" & inTxtCust.Text & _
"' and LocationID = '" & inTxtLocID.Text & "';"
Else
strsql = "DELETE from TmpPrtTkt WHERE LocationID = '" & inTxtLocID.Text & "';"

End If
RSGConn.Execute(strsql)
RSGConn.Close()
End Sub

Public Sub ExportData(ByRef oRpt As Object)
Dim fs As IO.FileStream
Dim FileSize As Long
Dim oDest As New CrystalDecisions.Shared.DiskFileDestinationOptions
Dim ExportFileName As String = "C:\Temp\" & strCustID & " Tickets.pdf"
'Server.MapPath("/") & System.Configuration.AppSettings("ExportDir") & Session.SessionID & ".pdf"
Try

oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
oRpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
oDest.DiskFileName = ExportFileName
oRpt.ExportOptions.DestinationOptions = oDest
oRpt.Export()
'Build Target Filename
'Send the file to the user that made the request
Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Type", "application/pdf")
fs = New IO.FileStream(ExportFileName, IO.FileMode.Open)
FileSize = fs.Length
Dim bBuffer(CInt(FileSize)) As Byte
fs.Read(bBuffer, 0, CInt(FileSize))
fs.Close()
Response.BinaryWrite(bBuffer)
Response.Flush()
Response.Close()

Catch e As Exception
End Try
End Sub


Good Luck. Cathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top