Solved

Render HTML from a string

Posted on 2002-07-27
5
602 Views
Last Modified: 2010-04-15
I have a windows app that checks URL response time of our various web sites.  Right now it just checks the URL response time by using the HttpWebRequest class and downloading the sites html.  

I want to add an option to render the html that was downloaded.  When the page is rendered it would obviously download all the images of the site and timing that would also be useful.

When I am finished downloading all the html it is stored into a string.  How can I render the html in this string.  At this time I do not intend on giving the user the option of viewing the rendered page so if it doesnt render 100% correct like it would in Internet Explorer its not a show stopper.  I am mainly concerned about the amount of time to download all the content from the html (images, etc).

Thanks
Darrell
0
Comment
Question by:larockd
5 Comments
 
LVL 1

Accepted Solution

by:
sdn421 earned 100 total points
ID: 7185702
You could write the string to a file and then open the file.

using System;
using System.IO;

string fileName = "myFile.htm";          
FileInfo file = new FileInfo(@"C:\acc" + fileName);

StreamWriter sw = file.CreateText();    
sw.WriteLine(htmlString);              
sw.Close();

You could also use an IE control as an ActiveX component.
Add a reference to "Microsoft Web Browser" in your project. You can then use this object to navigate and display the web page.

I am not sure if this is what you are looking for.  Let me know if you need something else.

Good Luck.

0
 

Author Comment

by:larockd
ID: 7186821
Basically what I am looking for is a way to render the page in the background.  It does not matter if the user sees the rendered page.  The whole purpose for the rendered page is to time how long it takes to download the whole page.

For example if you have two pages and they each display one image and the one page's image is 5K and the other pages image is 5 megs then the time it takes to download each page's html will be close, but the amount of time to download the pages associated parts (images) will dramitically differ for both those pages.

I am interested in using the activeX web browser control how would you do that?

dl
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 7241536
With your approach, you will always have to wait until the page has finished loading until you know how long it takes. And the time you measure may be completely wrong in several situations: if the user is downloading something else from the net, or if the server or connection to it is unusually slow.

Therefore, what I would do to solve your task, is to parse that HTML file yourself, finding any IMG, LINK REL, EMBED, OBJECT etc. tags, then request these with a HEAD request (which will return the content size without actually downloading it). Add all the sizes together (plus some bytes for protocol overhead if you want accurate numbers) and divide it by the speed of the targeted connection (e.g. how fast would it be on a cable connection, or on a crappy old 28'800 modem?).
0
 

Author Comment

by:larockd
ID: 7243272
AvonWyss,

The reasons you site for the time being skewed is exactly what my program is attempting to monitor.  My program is not intended to give you an ideal response of a webpage load, but it is intended to alert you to problems such as poor connections, saturated paths, etc.  

Darrell
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9506469
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept a comment by sdn421
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheAvenger
EE Cleanup Volunteer
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question