Solved

Render HTML from a string

Posted on 2002-07-27
5
603 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What namespace do I need to import? 2 38
2 questions 10 29
Printing 1 59
updating order of the rows, N+1 query issue, C#, asp.net, MVC, SQL Server 3 34
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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