0

I'm using win-forms WebControl (tried also the built-in WPF browser) , and it's content are simple html and JavaScript files that defined as embedded resource.

For my POC all of the files must be Embedded.

XAML :

<Window x:Class="WebPOC.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    Title="MainWindow" Height="350" Width="525">
<Grid>
  <WindowsFormsHost>
    <forms:WebBrowser  x:Name="WebBrowser"/>
  </WindowsFormsHost>
</Grid>

Code-Behind:

public MainWindow()
{
   InitializeComponent();
   var stream = Assembly.GetEntryAssembly().GetManifestResourceStream("WebPOC.www.index.html");
   WebBrowser.DocumentStream = stream;
}

Web Content:

alert("test");
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <script src="js/test.js"></script>
    <title></title>
</head>
<body>
    <p>test</p>
</body>
</html>

For some reason the linked JavaScript file gives an error:

enter image description here

Any Ideas?

  • It is looking for the embedded js in a wrong place and there is no way it to know to get it from embedded resources unless you explicitly set them. [check this](http://stackoverflow.com/questions/9934357/how-to-load-html-javascript-from-embedded-resource-into-winform-web-browser) – Oguz Ozgul Nov 30 '15 at 10:55

1 Answers1

0

In your application, your WebBrowser load an HTML page. that page is from resources, it does not matter at this time. Now webbrowser wants to render your page and parse the HTML. While parsing it, it understand it has to load a further "file" js/test.js, which I assume is stored in your resources as well. Your webBrowser has no idea that he need to load js/test.js from resources, I think he is trying to send an HTTP request somehow, that will fail.

Short answer: don't use embedded resources for HTML files linking each other: your instanciated webBrowser will not be able to navigate between them

Gian Paolo
  • 4,161
  • 4
  • 16
  • 34
  • Thanks for the reply! , I assumed that was the problem , So , The WebControl doesn't support embedded resources? – Moti Elbilya Nov 30 '15 at 14:22
  • webControl can load a stream, so also a stream coming form your embedded resource (that's what you are doing right now). But webControl work is to handle HTML, and in HTML you have no way to say "load this from myResource". maybe you can work out webControl, intercepting Navigate Events (maybe beforeNavigate?) and handling them serving your internal result. But really, I think you are forcing the webbrowser control working in a way it's not meant to work – Gian Paolo Nov 30 '15 at 15:23