Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify relative file path in VB.net

I have a Webbrowser control in a form which displays a pdf file. I have to specify the URL as the file location on my computer.

eg.

 E:\Folder\Manual.pdf

Both the pdf file and the program are in the same folder.

How do I specify the URL so that when I move the folder onto another drive, it opens the same pdf file?

like image 827
user155312 Avatar asked Aug 08 '14 02:08

user155312


People also ask

How do you specify a relative path?

Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy. A single dot represents the current directory itself.

How do I change the path of a file in Visual Basic?

Exploring the IDE settings In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.

What is a relative path Example?

A relative path is a way to specify the location of a directory relative to another directory. For example, suppose your documents are in C:\Sample\Documents and your index is in C:\Sample\Index. The absolute path for the documents would be C:\Sample\Documents.


2 Answers

The location of your application is

 Dim path as String = My.Application.Info.DirectoryPath 

The you could use:

Dim pdffile as String = IO.Path.Combine(path, "pdffile.pdf")
WebBrowser1.Navigate(pdffile)
like image 180
Nizam Avatar answered Oct 01 '22 18:10

Nizam


If I understand you correctly, then:

Dim myPdf As String = 
    IO.Path.Combine(IO.Directory.GetParent(Application.ExecutablePath).FullName, "myPdfFile.pdf")
like image 42
OneFineDay Avatar answered Oct 01 '22 17:10

OneFineDay