path inside project

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
I have a directory listbox, I try to set the path to a directory inside the project. how do I do that?
 
To get the path of the Application

VB.NET:
Dim Path As String = My.Application.Info.DirectoryPath
 
Ok, my thought was to add som pdf files to my project as embedded files, then list them up in a listbox at runtime, I have added 1 file at the moment, and set the property to embedded resource and do not copy in the field Copy to Output Directory.
But when I added the path that was listet over here the file did not show in the listbox aming the others. Can someone please give me a hint here?
 
I now have listed the files in the listbox, I figured it out.
But now I got another problem.

I am now trying to open a file, I use a button and in the buttonClick event
I put the code:

VB.NET:
Dim myPdfFile As String = ListBox1.SelectedItem 
Me.AxAcroPDF1.src = myPdfFile

I have checked the myPdfFile with a msgBox and it shows the name of the file I have selected in the listbox, but the file do not open when I run the code:
VB.NET:
Me.AxAcroPDF1.src = myPdfFile

If I set the code like:
VB.NET:
Me.AxAcroPDF1.src = "C:\abc.pdf"
the file opens just fine.

How can I set the path to file to make the file open.
The file is located in: My.Application.Info.DirectoryPath
 
Last edited:
VB.NET:
If System.IO.File.Exists(YourPath) Then
            Dim P As New Process
            P.StartInfo.FileName = YourPath
            P.StartInfo.Verb = "Open"
            P.Start()
        End If
 
Ok Now I fixed that as well, but somhow the problems does not seem to stop coming.
The files I embedded and uses when I build my project does not "follow" when I publish my project, why is that? What am I missing here?
 
Remember these are virtual paths!

Whilst in development the files will be held in either the Debug or Release directories, but once installed on the client it will appear under the install path.

This is how I save a pdf...

VB.NET:
Dim Path As String = My.Application.Info.DirectoryPath
            If Not Directory.Exists(Path & "\Temp_PDF") Then
                Directory.CreateDirectory(Path & "\Temp_PDF")
            End If

            If File.Exists(Path & "\Temp_PDF\" & ReportName & ".pdf") Then
                Try
                    File.Delete(Path & "\Temp_PDF\" & ReportName & ".pdf")
                Catch ex As Exception
                    Return "Error - " & ex.Message
                End Try

            End If

            Dim vFileName As String = Path & "\Temp_PDF\" & ReportName & ".pdf"

If you both save and retrieve the file using DirectoryPath it will work both in development and release.
 
I am not shure I understand your code right but if I change the Temp_PDF with the right filename it will then save that file to the right location when I install my program?

Or is there another way to include th files?
 
Back
Top