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?
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.
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.
来源:https://stackoverflow.com/questions/4606901/opening-local-files-in-webkit-net