J'avais fait un truc dans le genre ya qqs temps.
J'ai pas lu attentivement le topic donc je ne sais pas si ton besoin est exactement le même
Mais voilà mon code
Je récupère le code html rendu dans htmlRender et j'appelle la méthode ReplaceImgSrc avec htmlRender en paramètre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 private void ReplaceImgSrc(string content) { string pattern = "<img\\s+[^>]*?src\\s*=\\s*(?:(?:\"(?<url>[^\"]*)\")|(?<url>[^>]*))"; var r = new Regex(pattern, (RegexOptions.IgnoreCase | RegexOptions.Compiled)); MatchCollection results; results = r.Matches(content); foreach (Match mat in results) { Group g = mat.Groups[1]; CaptureCollection cc = g.Captures; foreach (Capture c in cc) { ParseSrc(c.Value); } } } private void ParseSrc(string value) { if (value.Contains("TempImages")) { htmlRender = htmlRender.Replace(value, string.Format("http://{0}{1}", HttpContext.Current.Server.MachineName.ToLower(), value)); } }
Partager