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?
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.
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.
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.
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)
If I understand you correctly, then:
Dim myPdf As String =
IO.Path.Combine(IO.Directory.GetParent(Application.ExecutablePath).FullName, "myPdfFile.pdf")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With