views:

489

answers:

1

If I generate some HTML and have it in a string and then say:

myWebBrowser.DocumentText = string;

It seems to work just fine, except none of the images load (I get the broken image graphic).

If, however, I write the string to a file and then say:

myWebBrowser.Url = new Uri("file://myfile.html");

Everything works just fine.

My question is, what's going on under the covers here that is different? I've verified in both cases that the path to the images (via RClick->View Source) is the same and that all the images do, indeed, exist.

In both cases the HTML is exactly the same.

Any light that could be shed on this would be appreciated. Thanks!

+3  A: 

The urls in the document text are most likely relative to the page you are on. With that said when you save to a file the urls are made absolute. You may want to add a <base href="Your.html" /> tag to your markup to make the image visible in the web browser.

The WebBrowser control resolves those relative images to their location and displays them accordingly.

Pat
This makes sense... all the paths I'm storing are relative. If I just set the HTML via DocumentText, what are they resolved relative to, I wonder?
jeffamaphone
Ah, it seems they are relative to about:blank!
jeffamaphone