Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



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

Posts: 107
Name: Rick Palmer
Trades: 0
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.
--------------


__________________

Please login or register to view this content. Registration is FREE
- free online training in Java, J2EE, and MySQL.


Please login or register to view this content. Registration is FREE
- answers and advice from a geek who knows stuff.
RickPlmr is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-22-2007, 06:47 PM Re: How do I set the entire HTML using MSHTML?
RickPlmr's Avatar
Super Talker

Posts: 107
Name: Rick Palmer
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
- free online training in Java, J2EE, and MySQL.


Please login or register to view this content. Registration is FREE
- answers and advice from a geek who knows stuff.
RickPlmr is offline
Reply With Quote
View Public Profile
 
Old 02-22-2007, 06:49 PM Re: How do I set the entire HTML using MSHTML?
RickPlmr's Avatar
Super Talker

Posts: 107
Name: Rick Palmer
Trades: 0
Anyone know of a good html syntax highlighter and formatter?
__________________

Please login or register to view this content. Registration is FREE
- free online training in Java, J2EE, and MySQL.


Please login or register to view this content. Registration is FREE
- 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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.14499 seconds with 12 queries