Forum Xamarin.Android

a local html file

RuiXRuiX PTMember ✭✭

I am using
setting the file primeira.html as content as we should at

but the requested file is never found...
I use this path

Can you help?


  • Take a look here, almost the same question: Extract HTML source code

  • RuiXRuiX PTMember ✭✭

    Thanks but what is the reference I should add at the start of the file in order to be able to use
    Android.Net.Uri uri = Android.Net.Uri.Parse(Path.Combine(Application.Context.FilesDir.Path, "subfolderA/subfolderAA", document.FileName));

  • CheesebaronCheesebaron DKInsider, University mod

    Why do you need to do that? Please elaborate.

  • RuiXRuiX PTMember ✭✭

    I´m using

    but I ant to use this... with Path.Combine, because I think that Path gets the local path until the file...
    //string fileName = "Content/Home.html"; // remember case-sensitive
    //string localHtmlUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
    //webView.LoadRequest(new NSUrlRequest(new NSUrl(localHtmlUrl, false)));

    nevertheless my app doesn't recognize Path or LoadRequest


  • CheesebaronCheesebaron DKInsider, University mod

    NSBundle? NSUrl? This is not iOS...

  • RuiXRuiX PTMember ✭✭

    Thanks. I understand and forget that code...
    But having "primeira.html" inside Resources, why Android doesn't find it with


    How can I write this path?

  • RuiXRuiX PTMember ✭✭

    I want a path for internal storage... also I forget this "android_asset"
    I create the html file inside the app

  • CheesebaronCheesebaron DKInsider, University mod

    You need to put your stuff inside of assets, otherwise you won't be able to read it.

  • xceedxceed GBMember ✭✭

    Would you need to set the build action to AndroidAsset?

  • RuiXRuiX PTMember ✭✭

    I will make some tests with your information.
    Then I will tell you what I was able to do.
    I send my screen attached.

  • SebastianSeidel.9226SebastianSeidel.9226 DEInsider, University ✭✭✭✭

    Depending on the size of your "primeira.html" you can copy the markup and store it inside a string.
    Doing so you can load your web-page like this:

        webView.LoadDataWithBaseURL("blub://yippi", "YOUR_STRING_HERE", null, "UTF-8", "");
  • RuiXRuiX PTMember ✭✭

    Thanks to all of you, the problem was solved!

  • SebastianSeidel.9226SebastianSeidel.9226 DEInsider, University ✭✭✭✭
    edited October 2014

    Glad you solved the problem. Are you willing to share the solution for a later reference if someone else can look it up here in the forum

  • RuiXRuiX PTMember ✭✭

    I used
    with the file inside assets and with the build action (right click the file) set to AndroidAsset

    All best

  • AlperSilistreAlperSilistre USMember

    I face with same issue and thanks for this topic. Xamarin documentation about loading html in to the WebView is wrong. It says put localWebView.LoadUrl("file:///android_asset/Content/Home.html"); but it shouldn't be Content. I am calling with localWebView.LoadUrl("file:///android_asset/Home.html");

  • JohnHoJohnHo USMember ✭✭

    I try to do the same thing in Share project with Xamarin form but it does not work(It works in Android project)
    what do I do wrong?

    public class helpPage : ContentPage
    public helpPage ()

            var source = new HtmlWebViewSource();
            //source.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
            //var assetManager = Xamarin.Forms.Forms.Context.Assets;
            //using (var streamReader = new StreamReader(assetManager.Open("local.html")))
             //   source.Html = streamReader.ReadToEnd();
            source.Html = @"<html><body>
                  <p>Welcome to WebView.</p>
            var _webView = new WebView
                Source = source,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand


Sign In or Register to comment.