0
votes

I have a pdf file Placed in the Resource folder. I want to display the PDF File using WebBrowser control. The Main Problem is to find the relative path of the PDF and convert it to absolute, since the WebBrowser dosnt support relative Path.

so far I have the following code(simplified version):

string GuidePath = "../Resources/Guide/LogViwer User Manual.pdf";
string fullPath = Path.GetFullPath(GuidePath);
Uri GuideURI = new Uri(fullPath, UriKind.Absolute);
Browser.Navigate(GuideURI);

'Browser' is aninstance of a WebBrowser.

The Exeption I get is:

Connot find ...Path... Make sure the path and Internet address is correct.

2

2 Answers

2
votes

in the file Properties "Copy to output" must be set to "copy if newer" and the Code must be edited to:

string GuidePath = @"./Resources/Guide/LogViwer User Manual.pdf";
1
votes

According to the WebBrowser class's documentation, the Navigate method expects a URI, not a filesystem path. You should be able to sort that out thanks to the Uri class:

Browser.Navigate(new Uri(fullPath));

Although I haven't tested that so no promises.