c# - How replace all links inside local files from mirror web site -



c# - How replace all links inside local files from mirror web site -

i download lot of files web site in c# webclient() local directory.

now want create console application(no web app) replace links within html pages portable web site readable on plateform (usb key, mobile, etc..), pages must opened browsers , link must valid.

link typed this:

site: http://www.domain.com

<a href="/fr/wol/b/r30/lp-f/rbi8/f/1995/31/">xxx</a> <a href="/fr/wol/b/r30/lp-f/rbi8/f/1995/66/21#h=134:288-135:0">zzz</a> <a href="/fr/wol/b/bc/r30/lp-f/1001060069/1026">yyy</a> <a href="/fr/wol/b/r30/lp-f/rbi8/f/1995/61/3#h=16:360-17:0">xxx1</a> <a href="/fr/wol/dx/r30/lp-f/1001060064/30652">xxx1</a> <a href="http://www.domain.com/fr/1001060064/30652">xxx1</a>

i don't want have kind of links:

<a href="file://c:/users/documents/site/fr/wol/b/r30/lp-f/rbi8/f/1995/31/">xxx</a>

because entire web site must located anywhere.

the goal have relative links this: (this illustration , it's not exact)

<a href="../../b/r30/lp-f/rbi8/f/1995/31/">xxx</a> <a href="../../b/r30/lp-f/rbi8/f/1995/66/21#h=134:288-135:0">zzz</a> <a href="../../../bc/r30/lp-f/1001060069/1026">yyy</a> <a href="../../b/r30/lp-f/rbi8/f/1995/61/3#h=16:360-17:0">xxx1</a> <a href="../wol/1001060064/30652">xxx1</a>

is exists in language .net windows form or console application (non web) c# create these relative links ?

sloppy , without error checking, should started.

public void editwebpages() { foreach(string file in directory.getfiles("insert_files_dir")) { string[] lines = file.readalllines(file); for(int i=0; i<lines.length; i++) lines[i] = lines[i].replace(regexgrab("href=\"(.*?)\"", lines[i]), "../../your/relative/link/"); file.writealllines(file, lines); } } public static string regexgrab(string reg, string txt) { regex regex = new regex(reg, regexoptions.singleline); match match = regex.match(txt); string str = match.groups[1].tostring(); homecoming str; }

c# html .net hyperlink

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -