2

I already browse this question but it was not very useful: WebBrowser control page load error (or maybe I didn't catch the thing)

I use a WebBrowser to display the content of a PDF in my application (C# .NET 4.5). I try to navigate into the local URL of the file (which I can open with the explorer) with this code:

m_path = pdfDoc.CreateReportFile();
try
{
   webBrowser1.Navigate(new Uri(m_path));
}
catch (Exception e)
{
    Console.WriteLine("{0} Exception caught.", e);
}

But the navigation is always canceled, even if I try to reload the page. No exception is thrown.

What can I do?

Here's the URL: C:\\Users\\me\\AppData\\Local\\Temp\\LY20_2014-11-25_06#22M1[1].pdf

If I paste it in IE, remove the escaping \, the file does open.

Update:

  • The webbrowser works fine when entering the string @"http://www.google.fr"
  • When using the PDF file address it opens it in Acrobat Reader after the Navigation Canceled message
Community
  • 1
  • 1
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
  • You do know that catching and rethrowing like that is of no use, don't you? Can you post the complete url? – Andrew Dec 01 '14 at 15:50
  • Did you try opening an existing PDF with the same code? – Martin Delille Dec 01 '14 at 16:34
  • @MartinDelille you mean replacing m_path with the PDF file? – Thomas Ayoub Dec 01 '14 at 17:41
  • no. Test your code without calling pdfDoc.CreateReportFile() and assign to *m_path* a valid PDF file path. – Martin Delille Dec 01 '14 at 19:16
  • Beware of double backslashes. Those should NOT be part of the string. Double backslashes are ONLY needed when you are typing a literal string in your code in order to escape the backslash and you are not using `@` before the quotes. Make sure your string is actually `C:\Users\me\AppData\Local\Temp\LY20_2014-11-25_06#22M1[1].pdf`. – Andrew Dec 01 '14 at 20:09
  • @MartinDelille it doesn't work either with a valid path :( – Thomas Ayoub Dec 02 '14 at 08:04
  • @Andrew the path is provided using `Path.GetTempPath()` so I assume the double backslashes are not an issue, furthermore when I right-click => Address the webbrowser, the right address is displayed – Thomas Ayoub Dec 02 '14 at 08:05
  • When you create the pdfDoc is it in read only mode or are freeing it to be use by any application ? – Maxime Mangel Dec 02 '14 at 08:25
  • @MaximeMangel I'm pretty sure it's not read only but I'll check again. I just updated the post – Thomas Ayoub Dec 02 '14 at 08:30
  • @Thomas Then I'll suggest you to remove the line concerning pdfDoc if you think it is not related to your problem. – Martin Delille Dec 02 '14 at 12:26

1 Answers1

0

Thanks to dear Adobe and Microsoft, we can't display a 32bits ActiveX in a 64bits WebBrowser at least, they are honest :

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142