Windows Develop Bookmark and Share   
 index > Windows Forms General > WebBrowser: setting manually Document.Body.InnerHtml
 

WebBrowser: setting manually Document.Body.InnerHtml

Hello,

I'm trying to implement a help in my test application. The home page of the help is defined in the configuration settings.

When no setting has been found, I would like to display "No help available". My problem is that WebBrowser.Document is readonly and by default Body is Nothing... How can I do that???

Thank's a lot
Serge
Serge Bollaerts  Sunday, June 19, 2005 9:14 AM

Perhaps the browser control doesn't have its Document property set, in which case it will throw a NullReferenceException.  You can use the DocumentText property to build the HTML manually. This is easier than working the DOM object model.


StringBuilder builder = new StringBuilder();

builder.Append("<html>");

builder.Append("<title>Help not installed.</title>");

builder.Append("<body>");

builder.Append("There is no help available.");

builder.Append("</body>");

builder.Append("</html>");

webBrowser1.DocumentText = builder.ToString();

HtmlDocument htmlDoc = webBrowser1.Document;


 



Another, better, option is to distribute a "No help available" html page with your application, and load this when there is no help setting:



webBrowser1.DocumentStream = File.Open(@"..\..\HelpNotInstalled.htm", FileMode.Open, FileAccess.Read);



 


durstin  Monday, June 20, 2005 5:30 PM

Perhaps the browser control doesn't have its Document property set, in which case it will throw a NullReferenceException.  You can use the DocumentText property to build the HTML manually. This is easier than working the DOM object model.


StringBuilder builder = new StringBuilder();

builder.Append("<html>");

builder.Append("<title>Help not installed.</title>");

builder.Append("<body>");

builder.Append("There is no help available.");

builder.Append("</body>");

builder.Append("</html>");

webBrowser1.DocumentText = builder.ToString();

HtmlDocument htmlDoc = webBrowser1.Document;


 



Another, better, option is to distribute a "No help available" html page with your application, and load this when there is no help setting:



webBrowser1.DocumentStream = File.Open(@"..\..\HelpNotInstalled.htm", FileMode.Open, FileAccess.Read);



 


durstin  Monday, June 20, 2005 5:30 PM

You can use google to search for other answers

Custom Search

More Threads

• How can I be notified of message loop start?
• User control
• Passing values from a tabcontol to another form
• i need a code for voice PC by internet(VoIP)
• Getting unused controles in the project
• DataGridview
• WebBrowser Control Leak
• Setting the size of the tab indent for a rich text box
• How to paint the bottom right space between custom scrollbars with color Control
• killing an executable at right time; when the file it creates is stable/full