all groups > dotnet academic > april 2004 >
You're in the

dotnet academic

group:

how do i reference deployment files in C#



Re: how do i reference deployment files in C# Dave Strickland
4/28/2004 9:50:41 AM
dotnet academic:
Take a look at

System.Windows.Forms.Application.StartupPath

This returns the directory which contains the EXE that started the
application. So

crystalReportViewer1.ReportSource =
System.Windows.Forms.Application.StartupPath + "\\\\Report.rpt";
would work if the EXE and Report.Rpt are in the same folder.

Since you said

[quoted text, click to view]

another option would be

crystalReportViewer1.ReportSource =
System.Windows.Forms.Application.UserAppDataPath + \\\\Report.rpt;


Good Look





[quoted text, click to view]

how do i reference deployment files in C# tigger
4/28/2004 2:10:17 PM
hi

i have a report which i wish to reference from within the program
this is what i am currently using which is fine on my local computer.
crystalReportViewer1.ReportSource = "C:\\\\Documents and
Settings\\\\Shaun\\\\My Documents\\\\Visual Studio
Projects\\\\ParcelPlus\\\\Report.rpt";

but i wish to deploy the program how do i reference the report after i have
deployed it.
i have created a deployment project and have added the Report.rpt file into
the User's Application Data Folder.

thanks
shaun


Re: how do i reference deployment files in C# Angus Entwhistle
4/28/2004 4:25:05 PM
Tip:

Rather than "System.Windows.Forms.Application.StartupPath +
"\\\\Report.rpt";" You should use ...

Path.Combine(System.Windows.Forms.Application.StartupPath, "Report.rpt");

Path.Combine will properly handle directory separators so that you don't
have to worry about them. You will always get a properly concatenated path
string.

Also, for constant strings that you don't need escaped, put a @ before the
string declaration and you can use regular old single backslashes. Makes
the code easier to read.

Instead of...

"C:\\\\Documents and Settings\\\\Shaun\\\\My Documents\\\\Visual Studio
Projects\\\\ParcelPlus\\\\Report.rpt"

use...

@"C:\Documents and Settings\Shaun\My Documents\Visual Studio
Projects\ParcelPlus\Report.rpt";

Note, that it won't work where you are expecting escaped characters to be
properly handled. For instance embedding a line feed in the string.

Console.WriteLine(@"Encountered the following error:\n");

will print the literal "\n" in the string because the string won't be
escaped.

--
Angus

AddThis Social Bookmark Button