Reply
How do I set the entire HTML using MSHTML?
Old 02-21-2007, 06:14 PM How do I set the entire HTML using MSHTML?
RickPlmr's Avatar
Super Talker

Posts: 107
Name: Rick Palmer
I'm working on an upgrade to my mail merge newsletter program, and am having a hard time figuring out how to set the entire document HTML using MSHTML in C#.

It seems from my own trials and numerous posts I've read, that the document.outerHTML property is read-only. So in my WYSIWYG html editor, when I try to allow a user to paste in their own HTML (with custom body tags, styles, etc) MSHTML replaces it with a vanilla <html><head></head><body> tag.

Here's a couple of things I'll be trying... has anyone else had success with these approaches? I'll post back later if I'm able to find a solution.

--------------
http://www.vbforums.com/showthread.php?p=2198670#post2198670

1. Make sure the document is loaded. (The DocumentCompleteEvent shows this.)
2. Get the AxWebBrowser.Document object and cast it to mshtml.IHTMLDocument2.
3. Set IHTMLDocument2.body.innerHTML property to the HTML string.

--------------

http://www.csharpfriends.com/Forums/...x?PostID=36601

casting the document to an IHtmlDocument2 object and using the document.write() method.
--------------


__________________
online-etraining - free online training in Java, J2EE, and MySQL.
rickysays - answers and advice from a geek who knows stuff.
RickPlmr is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 02-22-2007, 05:47 PM Re: How do I set the entire HTML using MSHTML?
RickPlmr's Avatar
Super Talker

Posts: 107
Name: Rick Palmer
I found a solution after a little trial and error.

The code below is the event handler for a tab control that tabs back and forth between a WYSIWYG Html editor and the HTML source:

PHP Code:
private void tabControl1_SelectedIndexChanged(object senderEventArgs e)
{
  
string html "<HTML><HEAD><TITLE></TITLE></HEAD><BODY></BODY></HTML>";
  switch (
tabControl1.SelectedIndex)
  {
    case 
0// Coming from Source tab
      
MSHTML.IHTMLDocument2 doc2 = (MSHTML.IHTMLDocument2)document;
      
doc2.open("about:blank"EMPTY_PARAMETEREMPTY_PARAMETEREMPTY_PARAMETER); 
      
doc2.expando true;
      if (
this.txtHtmlSource.Text != string.Empty)
      {
        
html this.txtHtmlSource.Text;
      }
      
doc2.write(html); 
      
doc2.close();
      break;
 
    case 
1// Coming from Design tab
      
MSHTML.IHTMLDocument3 doc3 = (MSHTML.IHTMLDocument3)document;
 
      if (
doc3.documentElement != null)
      {
        
html doc3.documentElement.outerHTML;
      }
 
      
html html.Replace(" contentEditable=true"""); //MSHTML enters this
      
this.txtHtmlSource.Text html;
      break;
    }
  } 
Basically, to set the full html I had to open a blank html document and then use the IHTMLDocument2 interface to write to its document.

On the reverse (getting the HTML), I used the IHTMLDocument3 interface.
__________________
online-etraining - free online training in Java, J2EE, and MySQL.
rickysays - answers and advice from a geek who knows stuff.
RickPlmr is offline
Reply With Quote
View Public Profile
 
Old 02-22-2007, 05:49 PM Re: How do I set the entire HTML using MSHTML?
RickPlmr's Avatar
Super Talker

Posts: 107
Name: Rick Palmer
Anyone know of a good html syntax highlighter and formatter?
__________________
online-etraining - free online training in Java, J2EE, and MySQL.
rickysays - answers and advice from a geek who knows stuff.
RickPlmr is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How do I set the entire HTML using MSHTML?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13014 seconds with 12 queries