locked
how to load external storage html file in web view

    Question

  • hi all,

        how to load external storage html file in web view, please help me

       " ms-appdata://local/index.html" not working


    veerasuthan veerakesan

    Wednesday, December 24, 2014 6:54 AM

Answers

All replies

  • It need be read as string. Then load the string by  Webview.NavigateToString.

    Sample as below

                string htmlstring = string.Empty;
                try
                {
                    var htmlfile = await Windows.Storage.ApplicationData.Current.LocalFolder.OpenStreamForReadAsync("a.html");
                    using (System.IO.StreamReader streamReader = new System.IO.StreamReader(htmlfile))
                    {
                        htmlstring = streamReader.ReadToEnd();
                    }
                    webview.NavigateToString(htmlstring);
                }
                catch(Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    • Marked as answer by govindrajan Friday, December 26, 2014 4:46 AM
    • Unmarked as answer by govindrajan Friday, December 26, 2014 4:46 AM
    Wednesday, December 24, 2014 4:55 PM
  • i need to retrieve all html content ( images, etc.... ) , this concepts only retrieve only string ....., so please provide another solution..... 

    veerasuthan veerakesan

    Friday, December 26, 2014 4:48 AM
  • webview.NavigateToString(htmlstring); <--- it will show wab page on webview

    Or if you want to parse html, please refer to : Parsing HTML in Windows Store Apps – Boredom Challenge Day 1


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Friday, December 26, 2014 2:48 PM
  • Basically, WebView can load the local resource from your app's local storage. If the resources are located outside of your app's local storage, you have 2 options:
    1) Copy the all resources to your local storage.
    2) Create a 'stream' that have all required resources, then give the stream to webview.

    2) is 'NavigateToLocalStreamUri' method.

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.buildlocalstreamuri

    This sample have more detail about using NavigateToLocalStreamUri.

    https://code.msdn.microsoft.com/windowsapps/XAML-WebView-control-sample-58ad63f7

    Saturday, January 03, 2015 4:55 PM