3

Is there a way to load a html as a string in webControl?

Something like:

webControl.Load("<!DOCTYPE html><html>...");

Like used in the normal wpf webControl:

webControl.NavigateToString("<!DOCTYPE html><html>...");
Jr_
  • 217
  • 4
  • 15
  • http://stackoverflow.com/q/4467219/1214743 , http://stackoverflow.com/q/5362591/1214743 , Have you googled this? – Malachi Feb 04 '15 at 18:20
  • 1
    But this only works with the normal webcontrol that comes with Visual Studio. Awesomium webControl doesn't have this property. – Jr_ Feb 04 '15 at 18:26

4 Answers4

9

Actually now I found the answer in the tutorials for C++ (not on .net wpf) in Awesomium site.

Here is my solution:

 var uri = new Uri("data:text/html,<!DOCTYPE html><html>...", UriKind.Absolute);

            webControl.Source = uri;
Jr_
  • 217
  • 4
  • 15
  • This fails if html string is too large. I'm getting an error: `Invalid URI: The Uri string is too long.` – Rahul Aug 12 '16 at 06:44
1

I know it is an old question but here is how I menaged to do it :

var page = new WebControl
{
    ViewType = WebViewType.Window,
};  
page.NativeViewInitialized += (s, e) =>
{
    page.LoadHTML("<html>SOME TEXT</html>");
};
Tunaki
  • 132,869
  • 46
  • 340
  • 423
MaLiN2223
  • 1,290
  • 3
  • 19
  • 40
0

Instead of using a URL in the source just put your HTML in there

Awsomium

loaded from Awesomium tutorials

Malachi
  • 3,205
  • 4
  • 29
  • 46
0

Here is my solution: Load html string to a file and then load page using webControl.Source property.

 public static string WriteHtmlToTempFile(string html)
 {
     var fileName = GetTempFileName("html");
     System.IO.File.WriteAllText(fileName, html);
     return fileName;

 }
 var strHtml = "<HTML> Hello World</HTML>";
 var file = Common.WriteHtmlToTempFile(strHtml);
 var wUri = new Uri(string.Format(@"file://{0}", file   ));
 webControl2.Source = wUri;
Gary Kindel
  • 17,071
  • 7
  • 49
  • 66