I’ve downloaded Lutz Roeder’s Html Writer for use in a .NET WinForms app in order to avoid the IE-dependency issues mentioned in other threads here on SO.
The HtmlControl class SaveHtml() method only seems to return the first two characters however, which (not surprisingly) are always ”
For now, I’ve implemented a workaround by adding a method to the HtmlControl class which simply returns the Document object’s inner HTML.
public string HtmlBodyInnerHtml {
get { return this.site.Document.GetBody().GetInnerHTML(); }
}
This is working for now, but I’m wondering if anyone else has had similar problems. I’d love to continue using the control, but if there’s some inherent problems with it that I’ll keep running into I’d rather know now.
Alternately, I may be using it incorrectly – is SaveHtml() not the appropriate method to call to retrieve the HTML source?
So, I figured this out. Lutz’s HTML Writer doesn’t behave well when it is executed in 64-bit mode. I imagine you are targeting “Any CPU” when you compile, as I was. Some of the Windows API calls made by Writer failed to work as expected when called from 64-bit code. This is due to the change in pointer sizes, which Lutz apparently did not guard against. Compiling to target x86-only may be an acceptable solution for you. If not, you can change the first struct member in the STATSTG struct in NativeMethods.cs from:
To the more correct:
And the problem with SaveHtml() should be fixed. I came across some other bugs in the Writer.exe application in x64 mode, so be aware that you might have to go track down other pInvoke-related bugs if you must support x64.