Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
|
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2003, 06:41 AM
Authorized User
 
Join Date: Aug 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Absolute Path in Crystal Report

I have a project, it has a Crystal report. But :

rptViewOrders.ReportSource = "C:\\Account Managers\\Accounting\\Reports\\rptOrders";

I don't like this !. because it's absolute path:

you can introduce me method what ge relative path

I have try some but not god .

Thank you very much

L.V.L
__________________
L.V.L
 
Old October 27th, 2003, 06:40 PM
Authorized User
 
Join Date: Oct 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to TEDY Send a message via MSN to TEDY
Default

Untyped with ReportDocument
Call the Load() method of the ReportDocument component. Pass it the fully qualified file path. Assign the ReportDocument object to the ReportSource property of the viewer.

Listing 2-2. Use the viewer to preview a report when the form is loaded.

Private Sub Form1_Load(ByVal sender As System.Object, _

??? ByVal e As System.EventArgs) Handles MyBase.Load

??? reportDocument1.Load("C:\MyReport1.rpt")

??? CrystalReportViewer1.ReportSource = reportDocument1

End Sub

Listing 2-3. Print a report directly to the printer when a menu option is selected.

Private Sub MenuPrint_Click(ByVal sender As System.Object, _

??? ByVal e As System.EventArgs) Handles MenuPrint.Click

??? reportDocument1.Load("C:\MyReport1.rpt")

??? reportDocument1.PrintToPrinter(1, False, 0, 0)

End Sub

Strongly-Typed with ReportDocument
ReportDocument components generate all the necessary code for declaring and instantiating the report object for you behind the scenes. There is only one line of code you have to write. Assign the report object to the ReportSource property of the viewer.

Listing 2-4. Use the viewer to preview a report when the form is loaded.

Private Sub Form1_Load(ByVal sender As System.Object, _

??????? ByVal e As System.EventArgs) Handles MyBase.Load

??? CrystalReportViewer1.ReportSource = reportDocument1

End Sub

Lising 2-5. Print a report directly to the printer when a menu option is selected.

Private Sub MenuPrint_Click(ByVal sender As System.Object, _

??????? ByVal e As System.EventArgs) Handles MenuPrint.Click

??? reportDocument1.PrintToPrinter(1, False, 0, 0)

End Sub

Untyped Using Code
If you are using the viewer, you have the option of setting the file path directly by using the Properties window or setting it in code. If you aren't using the viewer, you have to instantiate a report object and call its Load() method. If you set the PropertySource property in the Properties window, then no coding is required. The viewer will load the report automatically.

Lising 2-6. Uses the viewer to preview a report when the form is loaded.

Private Sub Form1_Load(ByVal sender As System.Object, _

??????? ByVal e As System.EventArgs) Handles MyBase.Load

??? CrystalReportViewer1.ReportSource = "C:\MyReport1.rpt"

End Sub

Listing 2-7. Prints a report directly to the printer when a menu option is selected.

Private Sub MenuPrint_Click(ByVal sender As System.Object, _

??????? ByVal e As System.EventArgs) Handles MenuPrint.Click

??? Dim myReport As New ReportDocument()

??? myReport.Load("C:\MyReport1.rpt")

??? 'Set any printer specific properties here

??? myReport.PrintToPrinter(1, False, 0, 0)

End Sub

Strongly-Typed Using Code
The code to instantiate the object and print or preview it is your responsibility. Create an object variable from the report class and instantiate it.

Listing 2-8. Use the viewer to preview a report when the form is loaded.

Private Sub Form1_Load(ByVal sender As System.Object, _

??????? ByVal e As System.EventArgs) Handles MyBase.Load

??? Dim myReport As New CrystalReport1()

??? 'Set any printer specific properties here

??? CrystalReportViewer1.ReportSource = myReport

End Sub

Listing 2-9. Print a report directly to the printer when a menu option is selected.

Private Sub MenuPrint_Click(ByVal sender As System.Object, _

??????? ByVal e As System.EventArgs) Handles MenuPrint.Click

??? Dim myReport As New CrystalReport1()

??? 'Set any printer specific properties here

??? myReport.PrintToPrinter(1, False, 0, 0)

End Sub



 
Old October 27th, 2003, 11:34 PM
Authorized User
 
Join Date: Aug 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

oh, but you don't understand mean that i want to ask .
I mean that : can We change Absolute Path by ralative path ? .

I don't like this:

rptReportViewer.ReportSource = "C:\\My Projects\\Accouting\\Reports\\rptAccounting.rpt";

Because this is absolute path, It's not good !
I like this more :

rptReportViewer.ReportSource = ???? + "\\rptAccounting.rpt";

This mean that it don't depend on Path.

Can you help me this ?

Thank you very much about your help



L.V.L
 
Old October 28th, 2003, 02:47 AM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

The way I got around with this problem was to have the absolute path to the folder that you have the reports in the Web.config and then code it in relativity to that. See if that helps you better. Should, as it decreases one level of inconsistency.

Prasad, G L

Dare to Be Different
       DTBD
 Prasad, G. Lukas
 
Old October 28th, 2003, 11:28 PM
Authorized User
 
Join Date: Aug 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much
Best wishes to you

L.V.L
 
Old August 19th, 2004, 05:50 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,
        You can use Application.StartupPath to get a relative path. This will give you a path to the executable, which while you're in debug mode will be in bin\Debug.

        So say for instance you wanted to get to the text file test.txt. You would type in
Application.StartupPath + @" \test.txt"

        BTW this @ tell visual studio to ignore the \ otherwise I'd write it with two backslashes






Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing folders with absolute path having chars ravishakya Pro Java 0 September 18th, 2006 01:51 AM
Relative and Absolute Path question Johnger Pro Visual Basic 2005 1 September 8th, 2006 10:45 AM
absolute path required?? atila Crystal Reports 0 April 29th, 2006 06:31 AM
VSProject need absolute path to the references acuze C# 0 April 18th, 2006 06:06 PM
Convert logical path to absolute path zoostar J2EE 1 April 15th, 2005 10:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.