Note that there are some explanatory texts on larger screens.

plurals
  1. POC# WebBrowser HTML with references to scripts and images
    text
    copied!<p>I'm writing a C# app using the WebBrowser control, and I want all content I display to come from embedded resources - not static local files, and not remote files.</p> <p>Setting the initial text of the control to an embedded HTML file works great with this code inspired by <a href="http://blog.topholt.com/2008/03/18/c-trick-load-embedded-resources-in-a-class-library/" rel="nofollow noreferrer">this post</a>:</p> <pre><code>browser.DocumentText=loadResourceText("myapp.index.html"); private string loadResourceText(string name) { Assembly assembly = Assembly.GetExecutingAssembly(); Stream stream = assembly.GetManifestResourceStream(name); StreamReader streamReader = new StreamReader(stream); String myText = streamReader.ReadToEnd(); return myText; } </code></pre> <p>As good as that is, files referred to in the HTML - javascript, images like <code>&lt;img src="whatever.png"/&gt;</code> etc, don't work. I found similar questions <a href="https://stackoverflow.com/questions/72103/how-do-i-reference-a-local-resource-in-generated-html-in-winforms-webbrowser-co#273840">here</a> and <a href="https://stackoverflow.com/questions/153748/webbrowser-control-from-net-how-to-inject-javascript">here</a>, but neither is asking <em>exactly</em> what I mean, namely referring to <em>embedded</em> resources in the exe, not files. </p> <p>I tried <code>res://...</code> and using a <code>&lt;base href='..."</code> but neither seemed to work (though I may have not got it right).</p> <p>Perhaps (following my own suggestion on <a href="https://stackoverflow.com/questions/72103/how-do-i-reference-a-local-resource-in-generated-html-in-winforms-webbrowser-co#273840">this question</a>), using a little embedded C# webserver is the only way... but I would have thought there is some trick to get this going?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload