Opening local files in Webkit .NET

前端 未结 7 1956
天涯浪人
天涯浪人 2021-01-20 11:33

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

相关标签:
7条回答
  • 2021-01-20 11:50

    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)
    
    0 讨论(0)
  • 2021-01-20 11:54

    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.

    0 讨论(0)
  • 2021-01-20 12:00

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

    0 讨论(0)
  • 2021-01-20 12:00

    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.

    0 讨论(0)
  • 2021-01-20 12:02

    Create a sample HTML page. Upload into my resources.

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

    0 讨论(0)
  • 2021-01-20 12:04

    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;
    
    0 讨论(0)
提交回复
热议问题