Opening local files in Webkit .NET
Asked Answered
E

7

3

A simple WebKitBrowser1.Navigate(localfilehere) doesn't work for some reason.

I tried adding "file://" to the URL but that didn't work either.

This seems ridiculous but is this functionality really not present?

Epifocal answered 5/1, 2011 at 17:6 Comment(0)
R
5

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;
Rumen answered 31/5, 2012 at 11:11 Comment(0)
E
3

"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.

Espy answered 27/1, 2011 at 1:10 Comment(0)
H
2

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)
Horrocks answered 13/12, 2012 at 19:0 Comment(0)
F
1

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.

Fulguration answered 27/2, 2011 at 1:43 Comment(0)
M
1

Create a sample HTML page. Upload into my resources.

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

Monogamous answered 20/10, 2011 at 21:55 Comment(0)
F
1

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"

Freemon answered 4/7, 2012 at 5:10 Comment(0)
L
0

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.

Labannah answered 5/1, 2011 at 17:29 Comment(2)
Are you changing all of the back slashes in the file name to forward slashed, too? file:///C:/Folder/SubFolder/Test.htmlTampere
I am having the same problem, I am changing slashes. I am able to use webkitBrowser.Navigate to display some html file, but then I am not able to load javascript referenced from this html. So I am not able to include jquery for instance.Liaoning

© 2022 - 2024 — McMap. All rights reserved.