How to load a local HTML-File into Webview
-
Friday, March 02, 2012 8:27 AMI still cannot load a local html file using webview.Navigate() method on Windows8 custom preview as the previous thread talked. I tried with FilePicker and the scheme "ms-appdata:"(for the html located on the appdata), but all doesn't work. Is there any way to load the local html into WebView control?
All Replies
-
Saturday, March 03, 2012 4:21 AMModerator
Hi Joe,
I wouldn't expect what you describe to work. The FilePicker will return a stream to the file the user selected but doesn't give access to the file itself. To load those you would need to read out the text and use NavigateToString.
For items within the app's package you'd use ms-appx (or better than hardcoding: use your app's BaseUri to build the URI). I would suggest hooking up the HTML in the designer first to make sure the basics work and then move to the programmatic Navigate after.
Please give this a try and then if you still have problems let us see exactly what you were doing.
--Rob
- Proposed As Answer by Rob CaplanMicrosoft Employee, Moderator Saturday, March 03, 2012 4:21 AM
-
Saturday, March 03, 2012 5:10 AMJust to add to Rob's note here about using ms-appx:// for your local package HTML...this currently (unfortunately) doesn't work in the Consumer Preview. We know this and are working on identifying the root causes.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others) -
Monday, March 05, 2012 5:43 AM
Thanks Rob & Tim.
I'm developing a reader application to read EPUB3 compatible books that contain HTML5+CSS3 files as its contents. I want to use webview.Navigate to present the local html files that are not packaged with the application. I tired to copy the files to to the app’s local ApplicationData storage and use ms-appdata scheme, but this doesn't work. Does the WebView support the usage?
-
Monday, March 05, 2012 4:10 PM
WebView currently does not support the ms-appx, ms-appdata protocols. It is something we are working on examining supporting.Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)- Marked As Answer by joe_guo Tuesday, March 06, 2012 2:12 AM
-
Friday, June 22, 2012 3:29 PM
Tim,
reading local files into WebView control (rather via file:///[path] syntax) is very important for us at Hyperionics as well. Please do add this ability... Thanks!
Greg
-
Friday, June 22, 2012 4:34 PM@Greg - the contents would have to be in your package or you'd need to load the streams and use NavigateToString. I haven't tried with using the file:/// syntax with something that is in the "My Documents" location and your app has all the required associations and capabilities though.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others) -
Friday, June 22, 2012 11:31 PM
Hi Tim,
I tried both:
wv1.Navigate(new Uri("file:///mydir/somefile.html"));
where mydir is a subdirectory of my package, and also tried giving it an absolute path like:
wv1.Navigate(new Uri("file:///C:/anotherdir/somefile.html"));
and it did not work - I'm getting only an empty WebView rectangle. I'm also working with WebView control on Android, and it has no problems loading and displaying local files. NavigateToString() method is useless to me - it won't display e.g. images included with HTML files.
Greg
- Edited by hyperionics Friday, June 22, 2012 11:32 PM
-
Saturday, June 23, 2012 4:25 AM
@Greg - for the first one (where your HTML exists in your package) you would use:
wv1.Navigate(new Uri("ms-appx-web:///mydir/myfile.html"));
For the one on c:\ it will not work given the security model of Metro style apps.Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)- Proposed As Answer by Prateek Jaiswal Monday, September 10, 2012 12:19 PM
-
Saturday, June 23, 2012 8:34 PM
OK, ms-appx-web:// works, but then I cannot delete/create files in a directory under my package location, and it won't read files from anywhere else... With all this paranoid security, it's impossible to use this thing. I think I'll stick with Android then.
Greg
-
Tuesday, November 06, 2012 7:07 PM
Tim,
We are porting an App from iOS/Android (that has a significant user base) that needs to display HTML/CSS/JS files downloaded from the web in a WebView. Because the files are user-specific, there is no way to place them in the Assets folder (say).
How can I load the downloaded files programmatically into the webview?
Thanks,
Armando
-
Friday, November 23, 2012 1:03 AMAny news on supporting the ms-appx, ms-appdata protocols in WebView?
-
Sunday, April 07, 2013 7:53 PMVery interesting solution: Local HTML Resources
-
Monday, May 20, 2013 12:54 PM
Hi Tim,
a lot of people are still waiting for more than a year for a solution of the problem:
How to display any stored HTML file in a WebView control?
It's realy hard to develop and sell apps under such conditions ...
SunnyApril


