繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> 如何把html中的相对路径变成绝对路径

如何把html中的相对路径变成绝对路径

2007-09-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:private static string ConvertToAbsoluteUrls (string HTML, Uri relativeLocation) { IHTMLDocument2 doc = new HTMLDocumentClass (); doc.write (new object [] { HTML }); doc.close (); foreach (IHTMLAnc...

private static string ConvertToAbsoluteUrls (string HTML, Uri relativeLocation) {

IHTMLDocument2 doc = new HTMLDocumentClass ();

doc.write (new object [] { HTML });

doc.close ();

foreach (IHTMLAnchorElement anchor in doc.links) {

IHTMLElement element = (IHTMLElement)anchor;

string href = (string)element.getAttribute ("href", 2);

if (href != null) {

Uri addr = new Uri (relativeLocation, href);

anchor.href = addr.AbsoluteUri;

}

}

foreach (IHTMLImgElement image in doc.images) {

IHTMLElement element = (IHTMLElement)image;

string src = (string)element.getAttribute ("src", 2);

if (src != null) {

Uri addr = new Uri (relativeLocation, src);

image.src = addr.AbsoluteUri;

}

}

string ret = doc.body.innerHTML;

return ret;

}

责任编辑:admin
相关文章