Answered by:
Relative Path & File Not Found

Question
-
I'm trying to create a ClickOnce Deployment Package for a WinForms Application, which contains a Crystal Report.
On my Development Box, I load the report from a relative path by using a function I created to get the path, based on where the file is within my project, as follows:
Public Function GetReportPath(ByVal ReportName As String) As String
Dim CurrentFolder As String = System.IO.Directory.GetCurrentDirectory()
For i = 1 To 2
CurrentFolder = System.IO.Directory.GetParent(CurrentFolder).FullName
Next
Return CurrentFolder & "\Reports\" & ReportName
End FunctionThis works fine on the Deveopment Machine; however, I get a "File Not Found" error when trying to load the report after publishing a Click-Once Deployment Package.
The reports are being published to the Network Folder, as they are set to have a
Build Action "Content"
Copy To Output "Always"How can I tell the application where to find the published reports?
Thank you for any help you can offer.
Thursday, April 28, 2011 7:32 PM
Answers
-
Hi HomeChef,
I think you will need to replace the relative path to the absolute path using the Application.StartupPath property.
If this suggestion cannot solve your problem, please tell me where the GetReportPath method placed in your project.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by HomeChef Monday, May 2, 2011 4:29 PM
Monday, May 2, 2011 4:00 AM
All replies
-
Hi HomeChef,
I think you will need to replace the relative path to the absolute path using the Application.StartupPath property.
If this suggestion cannot solve your problem, please tell me where the GetReportPath method placed in your project.
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by HomeChef Monday, May 2, 2011 4:29 PM
Monday, May 2, 2011 4:00 AM -
Thank you. Just when I had figured I'd use the following "duh" workaround:
if file.exists(GetReportPath("myreport.rpt")) then
rptpath = GetReportPath("myreport.rpt")
else
rptpath = "Reports\.."
end ifI found your solution to be much cleaner, and it worked like a charm. Thank you.
Monday, May 2, 2011 4:35 PM -
You're welcome!
Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, May 3, 2011 3:31 AM