locked
Running downloaded HTML content in local storage RRS feed

  • Question

  • We have an application that needs to download an HTML package and store it in ApplicationData.Current.LocalFolder. It is stored in the standard manner with a top level directory containing an index.html and referenced images, css and javascript files. Firstly we could not view any images but that was semi-solved here. We can successfully load the index.html in a WebView by using the NavigateToLocalStreamUri method. However the index.html cannot resolve any locally referenced css or javascript files. 

    It is not an option for us to move the HTML package within the application as it is dynamic and downloaded at runtime. The NavigateToLocalStreamUri documentation mentions the ability to reference local css, images and javascript files but I see no example code using pplicationData.Current.LocalFolder anywhere. This is getting most frustrating, confusing and time consuming. Thanks for any help.

    Thanks


    Mike Palmer

    Wednesday, October 30, 2013 11:04 PM

Answers

  • Hi,

    As you mentioned, You can encode image as base64 string to display pictures. You can aslo encode css to base64 string aslo. Forexample

    The following code will display a blue square on the page instead of red

    <!doctype html>
    <html>
    <head>
    	<meta charset="utf-8">
    	<style>
    		#main{background:red;width:400px;height:400px;}
    	</style>
    	<link rel="stylesheet" href="data:text/css;base64,I21haW57YmFja2dyb3VuZDpibHVlO30NCg==">
    </head>
    <body>
    	<div id="main" role="main">
    	</div>
    </body>
    </html>

    You may needs to do some dirty work to fix links inside css


    Thursday, October 31, 2013 2:53 AM

All replies

  • For those with this problem we are currently using: 

    webBrowser1.Navigate(new Uri("ms-appdata:///local/dir/index.html"));

    This seems to be working. Still digging in...


    Mike Palmer

    Wednesday, October 30, 2013 11:23 PM
  • Hi,

    As you mentioned, You can encode image as base64 string to display pictures. You can aslo encode css to base64 string aslo. Forexample

    The following code will display a blue square on the page instead of red

    <!doctype html>
    <html>
    <head>
    	<meta charset="utf-8">
    	<style>
    		#main{background:red;width:400px;height:400px;}
    	</style>
    	<link rel="stylesheet" href="data:text/css;base64,I21haW57YmFja2dyb3VuZDpibHVlO30NCg==">
    </head>
    <body>
    	<div id="main" role="main">
    	</div>
    </body>
    </html>

    You may needs to do some dirty work to fix links inside css


    Thursday, October 31, 2013 2:53 AM