views:

139

answers:

1

I have a .NET 2.0 app (using C#) that shows some dynamically constructed HTML pages, some of which contain Silverlight. Here's a simple example of the HTML (Note, I am using absolute paths):

<html>
    <head></head>
    <body>   
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
            <param name="source" value="file:///c:/foo/bar/test.xap"/>
            <param name="onError" value="onSilverlightError" />
            <param name="background" value="yellow" />
            <param name="minRuntimeVersion" value="4.0.50401.0" />
            <param name="autoUpgrade" value="true" />
        </object>
    </body>
</html>

If I have my WebBrowser Control load a local file containing this, it works fine:

WebBrowser browser = new WebBrowser();
browser.Url = new Uri("file:///C:/foo/bar/simpleExample.html");

However, if I set DocumentText using the exact same HTML, the Silverlight app won't load. It appears the plugin loads (if you right click, it'll say "Silverlight"), but the content does not. I'm using a very simple Silverlight app.

WebBrowser browser = new WebBrowser();
browser.DocumentText = "<html>...same HTML as above...</html>

I would greatly prefer to use the latter method and not have to use local files. Any idea why I would see these differences? I also tried the same situation using Silverlight.js to have Javascript dynamically embed Silverlight but got the same result.

+3  A: 

When you set DocumentText the base url is changed to about:blank. To change that, add a base tag or set the document stream to a stream which also implement IMoniker::GetDisplayName to return the base URL.

Sheng Jiang 蒋晟
The Document stream idea is very interesting! Good to know. I'm still curious though why Silverlight behaves differently when the url is about:blank.
Newtang
security zone I guess. about:blank is in the internet zone, which does not have access to files in the local computer zone
Sheng Jiang 蒋晟