Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)delv
published in(发表于) 2014/1/6 9:06:30
C#如何把html中的相对路径变成绝对路径_[Asp.Net教程]

C#如何把html中的相对路径变成绝对路径_[Asp.Net教程]

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;
}


来源:网络







If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759