Windowscommunitytoolkit: 0x80004004 (E_ABORT)) Open file from Hard Disk

Created on 13 Jul 2018  路  9Comments  路  Source: windows-toolkit/WindowsCommunityToolkit

Hello:
I have a problem in windows forms opening a JS and HTML project from within the computer storage unit on my project. I have tried JS and HTML in Microsoft Edge and Firefox and it works normally but when I open the project in windows form using Microsoft.Toolkit.Win32.UI.Controls it gives me this error:

WebView by design controls win

Most helpful comment

NavigateToString is great if you have content that has only external references or embedded resources. If you have relative resources or links, you can also try the NavigateToLocal method on the WebView. In 4.0 a new API exists that allows you to control how resources are loaded NavigateToLocalStreamUri. See #2195 and #2194

All 9 comments

Thanks for reporting the issue! Can you provide us with more information to replicate it? Such as the version of the toolkit you're using or a file that provokes the error?

Please try to follow the issue template next time as it helps us analyze the issue and provide a solution.

@rjmurillo can you take a look at this?

yes
i download NuGet package from Microsoft v 3.0.0
my script in c#
`using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace webgl_3d_game_engine
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        webView1.Navigate(new Uri(@"file:///F:/Projects/js/IndigoCS-webgl-tutorials-master/Phong%20Lighting%20Intro/index.html"));
    }



}

}
`
the Exception:
System.Exception: 'Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))'
and vs 2017 open WebViewControlHost.cs in line 477.
.
and Iam sorry for my English

I just noticed this specific case is listed on the known issues of the webview control. Here is the workaround.

WebView controls don't recognize the File:// prefix. If you want to read a file into a WebView control, add code to your application that reads the content of the file. Then, serialize that content into a string, and call the NavigateToString(String) method of the WebView control.

Closing as it is a known issue.

Thank you for explaining things to me.

NavigateToString is great if you have content that has only external references or embedded resources. If you have relative resources or links, you can also try the NavigateToLocal method on the WebView. In 4.0 a new API exists that allows you to control how resources are loaded NavigateToLocalStreamUri. See #2195 and #2194

@rjmurillo
Well, but I do not understand how to use this because I have not used Web View before. Can you give me a source of learning or steps to convert a file extension to a "Web View" because I've searched for a continuous day but I did not know how. and I would be thankful to you.

@Ali1Jamal Here's a couple of examples. Given you have an application called MyWebView.exe in a folder C:\Apps\WebView, you could

  • Navigate to content relative to the application (C:\Apps\WebView\Content.html) by calling NavigateToLocal('/Content.html').
  • Navigate to content arbitrarily placed on the file system with NavigateToLocalStreamUri(Uri, IUriToStreamResolver) where the Uri is a relative URI (e.g. new Uri("/Content.html", UriKind.Relative)) and IUriToStreamResolver is an implementation of that interface, e.g. NavigateToLocalStreamUri(new Uri("/Content.html", UriKind.Relative), new CustomUriToStreamResolver()). The implementation will be called when any relative URI is resolved and is responsible for providing a System.IO.Stream of content to be consumed. Mostly this consists of translating the relative path to something that can be opened (e.g. System.IO.File.Open(...). See UriToLocalStreamResolver.cs as an example.

@rjmurillo
work fine thank you. here is a webgl picture in this link.
https://imgur.com/HtqXIHB

@rjmurillo

can you please help me with NavigateToLocalStreamURri? I have the same issue with my code. I can navigate to the local html files using Navigate(new Url (@"C://")) in Windows 7, but in Windows 10 it returns an error similar to the one you mentioned.

I tried using NavigatetToLocalStreamUri but I have no prior experience in using a webview hence cant understand what should be the parameters. Can you help me out with an example?

Was this page helpful?
0 / 5 - 0 ratings