Relative to absolute paths in HTML (asp.net) -
i need create newsletters url. next:
- create webclient;
- use webclient's method downloaddata source of page in byte array;
- get string source-html byte array , set newsletter content.
but have troubles paths. elements' sources relative (/img/welcome.png) need absolute (http://www.mysite.com/img/welcome.png).
how can this?
best regards, alex.
one of possible ways resolve task use htmlagilitypack library.
some example (fix links):
webclient client = new webclient(); byte[] requesthtml = client.downloaddata(sourceurl); string sourcehtml = new utf8encoding().getstring(requesthtml); htmldocument htmldoc = new htmldocument(); htmldoc.loadhtml(sourcehtml); foreach (htmlnode link in htmldoc.documentnode.selectnodes("//a[@href]")) { if (!string.isnullorempty(link.attributes["href"].value)) { htmlattribute att = link.attributes["href"]; att.value = this.absoluteurlbyrelative(att.value); } }
Comments
Post a Comment