In article <a3f6c32f.0309230607.50034f0a@posting.google.com >,
philipl@vistatec.ie says...[color=blue]
> "Pete" <pvidler@gawab.com> wrote in message news:<wmVbb.261$Yy4.149@newsfep3-gui.server.ntli.net>...[color=green]
> > Hi,
> >
> >
philipl@vistatec.ie wrote:[color=darkred]
> > > Does anyone have any sample code for this?? I can't find anything
> > > relvant at all. Please share out some code if you have any.[/color]
> >
> > A simple google search yields quite a few good results. I suggest you learn
> > to improve your searching technique.
> >
> > Or did you want someone to do it for you?
> >
> > -- Pete[/color]
>
>
> ehh... did you look at those results??? If you have found anything
> useful, pass it on, as I certainly couldn't, find anything more then 5
> lines of code.
> Otherwise quit spreading negative vibes.
>[/color]
Hi, here is a little example. I used this code to read an HTML page and
to replace some of the links in there, and after that to save the
result. The example is not full, but shows how to manipulate HTML page.
Hope that helps
Sunny
<snip>
try
{
mr = new StreamReader(source.OpenRead(sUrl));
sWebPage = mr.ReadToEnd();
}
catch
{ //could not read the URL
return;
}
finally
{
if (mr != null)
mr.Close();
}
HTMLDocumentClass myDoc;
try
{ //place the HTML string in MSHTML doc
object[] oPageText = {sWebPage};
myDoc = new HTMLDocumentClass();
IHTMLDocument2 oMyDoc = (IHTMLDocument2)myDoc;
oMyDoc.write(oPageText);
}
catch
{
//page is not well formated, skip it
return;
}
// if we are here, we have read the page and we are ready to parce it
//get collection of links
IHTMLElementCollection cMyLinks = (IHTMLElementCollection)myDoc.links;
//modify the links
foreach (IHTMLAnchorElement oLink in cMyLinks)
oLink.href = SubstituteTags(true, sUrl, oLink.href);
//get collection of images
cMyLinks = (IHTMLElementCollection)myDoc.images;
//modify images
foreach (IHTMLImgElement oImage in cMyLinks)
oImage.src = SubstituteTags(false, sUrl, oImage.href);
//write the result
StreamWriter myFile = null;
sWebPage = myDoc.documentElement.outerHTML;
try
{
myFile = new StreamWriter("modpage.html", false);
myFile.Write(sWebPage);
}
catch{}
finally
{
if (myFile != null)
myFile.Close();
}
<snip>