Opening local files in Webkit .NET

廉价感情. 提交于 2019-12-01 22:20:08
Gareev Kamil

Its look like you put wrong url. You can check it by

Uri.IsWellFormedUriString

One of the reasons - you put the string with national symbols.

In this case the answers before do not resolve you problem, because you also should encode url.

You can use System.Web.HttpUtility.UrlEncode for it and then apply a solution described before by X Enterprises (but you should not replace spaces - it would be already done by encoding) .

But the easiest way to get correct url is

string url = new Uri(pathToFile, UriKind.Absolute).AbsoluteUri;

"file://" is the correct protocol. To get to a file say in... "c:\temp\test.html" you can try something like:

"file://c/temp/test.html"

Note the forward slash and the absence of the colon after the drive letter.

dprahut

WebKit.Net 0.5 Navigate() function takes string as its parameter(local/web files). For local file for e.g: c:\xxx\yyy zzz.htm can be passed to Navigate Function as follows:-

dim sFile As String = "c:\xxx\yyy zzz.htm"
Dim url as new Uri(sFile, UriKind.Absolute)

'Now pass the file's required formatted absolute path
WebKitBrowser1.Navigate(url.AbsoluteUri)

I have found a solution to your problem:

1.) Make sure the path begins with "file:///"
2.) Make sure you use the file's full path
3.) Make sure all backslashes are changed to forward slashes
4.) Make sure you replace all spaces, " ", with "%20"
5.) Make sure the file ends in ".html"

So, a file here:
"C:\Program Files\test.html"
would need to become:
"file:///C:/Program%20Files/test.html"

Hope this helps.

Create a sample HTML page. Upload into my resources.

Use this code: WebKitBrowser1.document.write(my.resources.page.html)

Suppose index.html is in bin/debug folder then

Use "file:///"+Environment.CurrentDirectory.Replace(@"\",@"/")+"/index.html"

Suppose index.html is in bin/debug and created folder like www then

Use "file:///"+Environment.CurrentDirectory.Replace(@"\",@"/")+"/www/index.html"

In Google Chrome you can open a local file by entering file:/// followed by the complet path of the file, so it is possible taht you need to use the same operator on Webkit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!