6

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?

1
  • Just use the fully qualified path in the url. It doesn't matter where it is then in relation to the exe Commented Aug 8, 2014 at 14:13

3 Answers 3

12

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Please add more details how does this help.
3

If I understand you correctly, then:

Dim myPdf As String = 
    IO.Path.Combine(IO.Directory.GetParent(Application.ExecutablePath).FullName, "myPdfFile.pdf")

1 Comment

I'm not the downvoter, but you're missing to import any library so Directory is not recognized by default framework
1

Another way you could do it is by using something like the code below;

Private Sub FamilyLocateFile_Click(sender As Object, e As EventArgs) Handles FamilyLocateFile.Click
    If LocateFamilyDialog.ShowDialog = DialogResult.OK Then
        FamilyWMP.URL = LocateFamilyDialog.FileName
    ElseIf LocateFamilyDialog.ShowDialog = DialogResult.Cancel Then
        MsgBox(MsgBoxStyle.Critical, "Error!")
    End If
End Sub

What this will do is play a file in a Windows Media Player ActiveX object. The file can be selected with an OpenFile Dialog, which in this case is called LocateFamilyDialog. You don't need the ElseIf part of the statement, but you will need to insert an open file dialog and a control that can display PDFs. I think it'll work with WebBrowsers, but I'm not sure.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.