Our virtual home

User Sample

Posted my piece of code to embed the IE WebBrowser control in .NET without wrapping DLL's [.NET] as a GDN User Sample In general it is a rework of the code posted here, but with some extensions I needed and without saving static html to temporary file to navigate to later. The crux of matter is how to define the correct Interop for IHTMLDocument2.Write().
Here is my working solution:

using System;
using System.Runtime.InteropServices;

namespace System.Windows.Forms.Html {
  [InterfaceType(ComInterfaceType.InterfaceIsDual), ComVisible(true),   Guid(@"332C4425-26CB-11D0-B483-00C04FD90119")]
  interface IHTMLDocument2 {
    ...     
    ///


 

    
    /// Write complete html doc content including markup.
    ///
    ///object[] containing the string(s)
    ///
    ///
    /// IHTMLDocument2 document = control.GetDocument();
    /// if (document != null) {
    /// document.Open("", null, null, null);
    /// object[] a = new object[]{"Hello world"};
    /// document.Write(a);
    /// document.Close();
    /// }
    ///

    ///

    void Write(
      [In, MarshalAs(UnmanagedType.SafeArray)] object[] psarray);
    ...
  }
}

 

 

May be there is an Interop Guy that is able to solve it in a more elegant way? Currently IJW. This functionality is covered by the control itself. Usage of that feature of IE Control looks like this:

htmlControl.Html = myHtmlString;
htmlControl.Navigate(null);

With this approach you will also get the NavigateXYZ() events to listen for further usage.

» Similar Posts

  1. InternetGetCookie() in .NET
  2. How to integate and far eastern briefly before Easter
  3. Strange XSL Transform Exception - figured out

» Comments

  • Mustafa avatar

    Hi, I am wondering if you could answer my question.I am using a modified version of RSS Bandit(changes done by others), and we are currently facing the following problem, the htmlDetail control doesn't display the summary of the selected RSS item, I have debugged the system and found that everything is working correctly, even the html is handed correctly to the HTMl property for the IE Control but oddly it doesn't display it.Here is the line of code in the MainGui.cs file:htmlDetail.HTML = (call to the formatting function);htmlDetail.Navigate(null);I have got a workaround by using the code you have mentioned in your post earlier: IHTMLDocument2 doc = htmlDetail.Document2;doc.open("",null,null,null);doc.write(new object[]{html});doc.close();And it will work and show the html.Can you think of anything that will prevent the IE Control from displaying its HTML content?Thank you for having the time to read this.Best Regards.

    Mustafa — Juni 3, 2007 7:32
  • TorstenR avatar

    You can find a more up-to-date version of the IEControl in our RSS Bandit project at sourceforge: http://dev.rssbandit.org. You should try that one.

    TorstenR — Juni 11, 2007 2:48
  • california drug northern rehab avatar

    I switched to RSSBandit after NewsGator and Outlook started having performance problems with the number of feeds that I was trying to process each day.

    california drug northern rehab — September 10, 2007 3:32
  • Comments are closed