Shawn
Shawn

Reputation: 31

Opening local files in Webkit .NET

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?

Upvotes: 3

Views: 5940

Answers (7)

dprahut
dprahut

Reputation: 41

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)

Upvotes: 2

Swapnil Nandgave
Swapnil Nandgave

Reputation: 11

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"

Upvotes: 1

Kamil Gareev
Kamil Gareev

Reputation: 146

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;

Upvotes: 5

kachan64
kachan64

Reputation: 11

Create a sample HTML page. Upload into my resources.

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

Upvotes: 1

Chance Snow
Chance Snow

Reputation: 2718

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.

Upvotes: 1

Perishable Dave
Perishable Dave

Reputation: 2868

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

Upvotes: 3

Doliveras
Doliveras

Reputation: 1769

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.

Upvotes: 0

Related Questions